(function($) { $.fn.slide = function(options) { var defaults = { slidecontainer: $('.slideinner a'), effect: 'easeinquint', //轮播图切换动画风格 imgeffectout: 'easeinexpo', //里面元素动画离开风格 autoruntime: 3000, slidespeed: 1000, imgslidespeed: 800, imgdelay: 50, //里面小元素动画延长时间执行 nav: true, //点点列表 autorun: true, prevbtn: $('a.prev'), nextbtn: $('a.next') }; var el = $(this), settings = $.extend({}, defaults, options), leftpos = 0, navlist = "", timer = null, imgpos = '', ismove = true; /* *slides 移动方法 * */ $.fn.changeslide = function(settings, pos) { $(this).animate({ left: pos + "%" }, { duration: settings.slidespeed, easing: settings.effect, complete: function() { ismove = true; } }); }; $.fn.clickchangeslide = function(settings, pos) { $(this).css({ 'left': pos + "%", opacity: .9 }).delay(10).animate({ opacity: '1' }, { duration: settings.slidespeed, easing: settings.effect, complete: function() { ismove = true; } }); }; /* * 小元素动画 * * */ $.fn.imganimate = function(delaytime, imgeffectin, pos, where, settings) { var el = $(this); switch (where) { case 'right': el.stop(true).css({ 'left': '100%', 'opacity': '0' }).delay(delaytime+15).animate({ left: pos, opacity: '1' }, { duration: settings.imgslidespeed, easing: imgeffectin, complete: function() { el.css('left', pos); } }); el.parent().siblings().children().animate({ left: '20%', opacity: '0' }, { duration: 500, easing: settings.imgeffectout, complete: function() { el.css('left', pos); } }); break; case 'left': el.stop(true).css({ 'left': '0%', 'opacity': '0' }).delay(delaytime+15).animate({ left: pos, opacity: '1' }, { duration: settings.imgslidespeed, easing: imgeffectin, complete: function() { el.css('left', pos); } }); el.parent().siblings().children().animate({ left: '50%', opacity: '0' }, { duration: 500, easing: settings.imgeffectout, complete: function() { el.css('left', pos); } }); break; }; }; /* * 向左移动方法 * */ $.fn.moveleft = function() { if (!ismove) { return; }; ismove = false; var el = $(this); index = $(settings.slidecontainer).parent().find('.active').attr("data-index"); if (index <= total && index > 1) { current = $(settings.slidecontainer).eq(index - 1); next = $(settings.slidecontainer).eq(index - 2); if (next) { current.removeclass("active"); next.addclass("active"); changenavlist(); }; pos = ((number(index) - 2) * 100) * -1; el.changeslide(settings, pos); el.find('.active').imgmovesetting('left'); } else { tolast('first'); } }; /* * 向右移动方法 * */ $.fn.moveright = function() { if (!ismove) { return; }; ismove = false; var el = $(this); index = $(settings.slidecontainer).parent().find('.active').attr("data-index"); if (index >= 1 && index < total) { current = $(settings.slidecontainer).eq(index - 1); next = $(settings.slidecontainer).eq(index); if (next) { current.removeclass("active"); next.addclass("active"); changenavlist(); }; pos = ((number(next.attr("data-index")) - 1) * 100) * -1; el.changeslide(settings, pos); el.find('.active').imgmovesetting('right'); } else { tolast('last'); } }; //切换点列表 function changenavlist() { if (settings.nav) { var index = el.find('.active').attr("data-index"); $(".navlistbox li a").removeclass("active").eq(index - 1).addclass("active"); } }; //自动切换 function autorun() { if (settings.autorun) { clearinterval(timer); timer = setinterval(function() { el.moveright(); }, settings.autoruntime); } }; /* * 根据索引值切换 * */ $.fn.moveto = function(index) { var el = $(this), movewhere = ''; el.children().eq(index - 1).addclass('active').siblings().removeclass('active'); pos = ((index - 1) * 100) * -1; el.clickchangeslide(settings, pos); var nowindex = $(".navlistbox li a.active").attr('data-index'); if (index < nowindex) { movewhere = 'left'; } else { movewhere = 'right'; }; $(".navlistbox li").eq(index - 1).children().addclass('active').parent().siblings().children().removeclass('active'); el.find('.active').imgmovesetting(movewhere); }; $.fn.imgmovesetting = function(movew) { var el = $(this); if (movew) { $.each(el.children('.moveelem'), function(i) { var arr = $(this).attr('rel').split(','); var thisdelay = arr[0] - 0; var imgeffectin = arr[1]; var thisimgpos = $(this).attr('offsetleft'); $(this).imganimate(thisdelay, imgeffectin, thisimgpos, movew, settings); }); }; }; function tolast(move) { switch (move) { case 'last': el.find('a:first').css('margin-left', (el.children().length * 100) + "%"); el.changeslide(settings, -el.children().length * 100); el.find('a:first').imgmovesetting('right'); settimeout(function() { el.css('left', '0%'); el.find('a:first').css('margin-left', '0'); el.find('a:first').addclass('active').siblings().removeclass('active'); changenavlist(); }, settings.slidespeed + 50); break; case 'first': el.find('a:last').css('margin-left', -(el.children().length * 100) + "%"); el.changeslide(settings, 100); el.find('a:last').imgmovesetting('left'); settimeout(function() { el.css('left', -((el.children().length - 1) * 100) + "%"); el.find('a:last').css('margin-left', '0'); el.find('a:last').addclass('active').siblings().removeclass('active'); changenavlist(); }, settings.slidespeed + 50); break; } }; settings.prevbtn.hover(function() { $(this).css('opacity', '1.1'); }, function() { $(this).css('opacity', '1.1'); }); settings.nextbtn.hover(function() { $(this).css('opacity', '1.1'); }, function() { $(this).css('opacity', '1.1'); }); settings.nextbtn.click(function() { el.moveright(); }); settings.prevbtn.click(function() { el.moveleft(); }); el.parent().hover(function() { settings.prevbtn.parent().show(); }, function() { autorun(); settings.prevbtn.parent().hide(); }); var total = $(settings.slidecontainer).length; $.fn.init(autorun()); $.each($(settings.slidecontainer), function(i) { $(this).css({ width: $(window).width(), position: "absolute", left: leftpos + "%" }).attr("data-index", i + 1); leftpos = leftpos + 100; if (settings.nav) { navlist += "
  • "; }; $.each($(this).children(), function(i) { $(this).attr('offsetleft', $(this).css('left')); }); }); $("").appendto(el.parent()); $(settings.slidecontainer).eq(0).addclass("active"); if (settings.nav) $(".navlistbox li a" + "[data-index=1]").addclass("active"); $(".navlistbox li a").bind({ click: function() { if (!ismove) { return; }; ismove = false; var index = $(this).attr('data-index'); el.moveto(index); }, mouseover: function() { $(this).parent().css('box-shadow', '0 0 5px #fff'); }, mouseout: function() { $(this).parent().css('box-shadow', 'none'); } }); }; })(jquery); /* * * 扩展jquery 动画组件 * */ jquery.easing['jswing'] = jquery.easing['swing']; jquery.extend(jquery.easing, { def: 'easeoutquad', swing: function(x, t, b, c, d) { //alert(jquery.easing.default); return jquery.easing[jquery.easing.def](x, t, b, c, d); }, easeinquad: function(x, t, b, c, d) { return c * (t /= d) * t + b; }, easeoutquad: function(x, t, b, c, d) { return -c * (t /= d) * (t - 2) + b; }, easeinoutquad: function(x, t, b, c, d) { if ((t /= d / 2) < 1) return c / 2 * t * t + b; return -c / 2 * ((--t) * (t - 2) - 1) + b; }, easeincubic: function(x, t, b, c, d) { return c * (t /= d) * t * t + b; }, easeoutcubic: function(x, t, b, c, d) { return c * ((t = t / d - 1) * t * t + 1) + b; }, easeinoutcubic: function(x, t, b, c, d) { if ((t /= d / 2) < 1) return c / 2 * t * t * t + b; return c / 2 * ((t -= 2) * t * t + 2) + b; }, easeinquart: function(x, t, b, c, d) { return c * (t /= d) * t * t * t + b; }, easeoutquart: function(x, t, b, c, d) { return -c * ((t = t / d - 1) * t * t * t - 1) + b; }, easeinoutquart: function(x, t, b, c, d) { if ((t /= d / 2) < 1) return c / 2 * t * t * t * t + b; return -c / 2 * ((t -= 2) * t * t * t - 2) + b; }, easeinquint: function(x, t, b, c, d) { return c * (t /= d) * t * t * t * t + b; }, easeoutquint: function(x, t, b, c, d) { return c * ((t = t / d - 1) * t * t * t * t + 1) + b; }, easeinoutquint: function(x, t, b, c, d) { if ((t /= d / 2) < 1) return c / 2 * t * t * t * t * t + b; return c / 2 * ((t -= 2) * t * t * t * t + 2) + b; }, easeinsine: function(x, t, b, c, d) { return -c * math.cos(t / d * (math.pi / 2)) + c + b; }, easeoutsine: function(x, t, b, c, d) { return c * math.sin(t / d * (math.pi / 2)) + b; }, easeinoutsine: function(x, t, b, c, d) { return -c / 2 * (math.cos(math.pi * t / d) - 1) + b; }, easeinexpo: function(x, t, b, c, d) { return (t == 0) ? b : c * math.pow(2, 10 * (t / d - 1)) + b; }, easeoutexpo: function(x, t, b, c, d) { return (t == d) ? b + c : c * (-math.pow(2, -10 * t / d) + 1) + b; }, easeinoutexpo: function(x, t, b, c, d) { if (t == 0) return b; if (t == d) return b + c; if ((t /= d / 2) < 1) return c / 2 * math.pow(2, 10 * (t - 1)) + b; return c / 2 * (-math.pow(2, -10 * --t) + 2) + b; }, easeincirc: function(x, t, b, c, d) { return -c * (math.sqrt(1 - (t /= d) * t) - 1) + b; }, easeoutcirc: function(x, t, b, c, d) { return c * math.sqrt(1 - (t = t / d - 1) * t) + b; }, easeinoutcirc: function(x, t, b, c, d) { if ((t /= d / 2) < 1) return -c / 2 * (math.sqrt(1 - t * t) - 1) + b; return c / 2 * (math.sqrt(1 - (t -= 2) * t) + 1) + b; }, easeinelastic: function(x, t, b, c, d) { var s = 1.70158; var p = 0; var a = c; if (t == 0) return b; if ((t /= d) == 1) return b + c; if (!p) p = d * .3; if (a < math.abs(c)) { a = c; var s = p / 4; } else var s = p / (2 * math.pi) * math.asin(c / a); return -(a * math.pow(2, 10 * (t -= 1)) * math.sin((t * d - s) * (2 * math.pi) / p)) + b; }, easeoutelastic: function(x, t, b, c, d) { var s = 1.70158; var p = 0; var a = c; if (t == 0) return b; if ((t /= d) == 1) return b + c; if (!p) p = d * .3; if (a < math.abs(c)) { a = c; var s = p / 4; } else var s = p / (2 * math.pi) * math.asin(c / a); return a * math.pow(2, -10 * t) * math.sin((t * d - s) * (2 * math.pi) / p) + c + b; }, easeinoutelastic: function(x, t, b, c, d) { var s = 1.70158; var p = 0; var a = c; if (t == 0) return b; if ((t /= d / 2) == 2) return b + c; if (!p) p = d * (.3 * 1.5); if (a < math.abs(c)) { a = c; var s = p / 4; } else var s = p / (2 * math.pi) * math.asin(c / a); if (t < 1) return -.5 * (a * math.pow(2, 10 * (t -= 1)) * math.sin((t * d - s) * (2 * math.pi) / p)) + b; return a * math.pow(2, -10 * (t -= 1)) * math.sin((t * d - s) * (2 * math.pi) / p) * .5 + c + b; }, easeinback: function(x, t, b, c, d, s) { if (s == undefined) s = 1.70158; return c * (t /= d) * t * ((s + 1) * t - s) + b; }, easeoutback: function(x, t, b, c, d, s) { if (s == undefined) s = 1.70158; return c * ((t = t / d - 1) * t * ((s + 1) * t + s) + 1) + b; }, easeinoutback: function(x, t, b, c, d, s) { if (s == undefined) s = 1.70158; if ((t /= d / 2) < 1) return c / 2 * (t * t * (((s *= (1.525)) + 1) * t - s)) + b; return c / 2 * ((t -= 2) * t * (((s *= (1.525)) + 1) * t + s) + 2) + b; }, easeinbounce: function(x, t, b, c, d) { return c - jquery.easing.easeoutbounce(x, d - t, 0, c, d) + b; }, easeoutbounce: function(x, t, b, c, d) { if ((t /= d) < (1 / 2.75)) { return c * (7.5625 * t * t) + b; } else if (t < (2 / 2.75)) { return c * (7.5625 * (t -= (1.5 / 2.75)) * t + .75) + b; } else if (t < (2.5 / 2.75)) { return c * (7.5625 * (t -= (2.25 / 2.75)) * t + .9375) + b; } else { return c * (7.5625 * (t -= (2.625 / 2.75)) * t + .984375) + b; } }, easeinoutbounce: function(x, t, b, c, d) { if (t < d / 2) return jquery.easing.easeinbounce(x, t * 2, 0, c, d) * .5 + b; return jquery.easing.easeoutbounce(x, t * 2 - d, 0, c, d) * .5 + c * .5 + b; } });