/*! sudyslides jQuery Plugin 2013-12-14 *@ version 1.0 *@ sudytech NatLiu */ (function($){ var defaults, Plugin, defaultName; defaultName = "sudyslides"; /* *定义可选参数,并设置默认值 */ defaults = { width: 1000, height: 380, responsive: true, start: 1, speed: 500, easing: "swing", effect: "slide", limitEffects: false, trigger: "click", container: { active: true, target: ".slides-slide", title: true, intro: true, url: true }, navigation: { active: false, hideHover: false, prev: { target: ".slides-prev", title: "Previous", text: "<", trigger: false, effect: false }, next: { target: ".slides-next", title: "Next", text: '>', trigger: false, effect: false } }, pagination: { active: true, target: ".slides-page", trigger: false, effect: false }, controls: { active: false, handles: { /* thumb: { active: true, target: ".slides-thumb", trigger: false, effect: false } */ } }, keyboard: { active: false, effect: false }, mousewheel: { active: false, effect: false }, touch: { active: true, speed: false }, autoplay: { active: true, interval: 3000, effect: false, autostart: true, hoverPause: true, timer: { active: false, trigger: ".timer-cycle", action: { active: false, actionFn: function(interval,element){} } }, player: { active: false, play: { target: ".player-play", title : "autoPlay", text: "Play", trigger: false }, stop: { target: ".player-stop", title: "stopPlay", text: "Stop", trigger: false } } }, effects: { slide: { speed: false, easing: false, direction: "leftRight" }, fade: { speed: false, easing: false, crossfade: true }, drift: { speed: false, easing: false, direction: "left", fadeout: false }, grids: { speed: false, easing: false, cols:15, rows:1, isRandom: false, outCss: "opacity", autoGroup: false, flash: false } }, callback: { preload: function(element){}, loaded: function(index,element){}, begin: function(current,index,element){}, complete: function(index,element){} } }; /* *构建插件对象 */ Plugin = (function(){ function Plugin(element, defaults, settings, pluginName){ this.element = element; this.defaults = defaults; this.settings = $.extend(true,{},defaults,settings); this.pluginName = pluginName; this._setup(); } return Plugin; })(); /* *setup */ Plugin.prototype._setup = function(){ $(this.element).hide(); this.settings.callback.preload($(this.element)); this.init(); } /* *初始化插件 */ Plugin.prototype.init = function(){ var _this = this, $e = $(this.element), $o = this.settings, $n = this.pluginName, $effects = this.limitEffects(); var $slides = $($o.container.target, $e).length > 0 ? $($o.container.target, $e) : $e.children(); if($o.container.active && $slides.length > 0){ $e.addClass($n); $.data(this, "total", $slides.length); $.data(this, "current", $o.start - 1); $.data(this, "effects", $effects); $.data(this, "size", {width: $o.width, height: $o.width}); $($slides, $e).wrapAll('
', $e).parent().css({ width: $o.width+'px', height: $o.height+'px', position: "relative", overflow: "hidden" }); var slidesTitle = [], slidesTime = [], slidesIntro = [], slidesUrl = [],slidesNum=[]; $.each($($slides, $e),function(i){ $(this).addClass('slides-slide slide-'+i).css({ width: "100%", height: "100%", position: "absolute", left: "0%", top: "0%", zIndex: 0, webkitBackfaceVisibility: "hidden", display: "none" }); slidesTitle[i] = $.trim($(this).attr("title")); slidesTime[i] = $.trim($(this).attr("time")); slidesNum[i] = $.trim($(this).attr("data-slides-num")); //console.log(slidesNum); slidesIntro[i] = $.trim($(this).attr("data-slides-intro")); slidesUrl[i] = $.trim($(this).attr("data-slides-Url")); if($o.container.url && slidesUrl[i]!=="#" && slidesUrl[i]!==""){ $(this).wrapInner(function(){ return $('',{ "class": "slide-url", "target": "_blank", "href": $.trim($(this).attr("data-slides-Url")) }); }); } }); $.data(this, "slidesTitle",slidesTitle); $.data(this, "slidesTitle1",slidesTitle); //下一组信息 $.data(this, "slidesTime",slidesTime); $.data(this, "slidesIntro",slidesIntro); $.data(this, "slidesIntro1",slidesIntro); //下一组信息 $.data(this, "slidesNum",slidesNum); //下一组信息 $.data(this, "slidesUrl",slidesUrl); if($o.container.title){ $("
").appendTo(".slides-container",$e); //$(".slides-container",$e).append("
"); /*下一组*/ //$(".slides-container",$e).append("
"); // 增加对应的下一组信息 } // if($o.container.intro){ // $("
").appendTo(".slides-container",$e); // } }else{ return false; } if($o.navigation.active){ var prevTrigger, prevEffect, nextTrigger, nextEffect; if($($o.navigation.prev.target, $e).length == 0){ $("
", { title: $o.navigation.prev.title, "class": "slides-prev navigation-handle" }).wrapInner(""+$o.navigation.prev.text+"").appendTo($e); }else{ $($o.navigation.prev.target, $e).addClass("slides-prev navigation-handle"); } if($($o.navigation.next.target, $e).length == 0){ $("",{ title: $o.navigation.next.title, "class": "slides-next navigation-handle" }).wrapInner(""+$o.navigation.next.text+"").appendTo($e); //}).wrapInner(""+$o.navigation.next.text+"").appendTo($e); }else{ $($o.navigation.next.target, $e).addClass("slides-next navigation-handle"); } $(".navigation-handle", $e).wrapAll("
"); if($o.navigation.hideHover){ $(".slides-navigation", $e).hide(); $e.hover(function(){ $(".slides-navigation", $e).show(); },function(){ $(".slides-navigation", $e).hide(); }); } prevTrigger = $o.navigation.prev.trigger ? $o.navigation.prev.trigger : $o.trigger; prevEffect = $o.navigation.prev.effect ? $o.navigation.prev.effect : $o.effect; $(".slides-prev", $e).on(prevTrigger,function(){ _this._stop(); return _this.showIndex(_this._prev(), prevEffect); }); nextTrigger = $o.navigation.next.trigger ? $o.navigation.next.trigger : $o.trigger; nextEffect = $o.navigation.next.effect ? $o.navigation.next.effect : $o.effect; $(".slides-next", $e).on(nextTrigger,function(){ _this._stop(); return _this.showIndex(_this._next(), nextEffect); }); } if($o.pagination.active){ var pageTrigger, pageEffect; if($($o.pagination.target, $e).length == 0){ $.each(new Array($.data(_this,"total")),function(i){ $("",{ "class": "slides-page pagination-item" }).wrapInner(""+(i+1)+"").appendTo($e); }); }else{ $($o.pagination.target, $e).addClass("pagination-item"); } $(".pagination-item", $e).each(function(i,e) { $(e).addClass("item-" + i); }).wrapAll("
"); $(".slides-pagination",$e).after("
"); pageTrigger = $o.pagination.trigger ? $o.pagination.trigger : $o.trigger; pageEffect = $o.pagination.effect ? $o.pagination.effect : $o.effect; $(".pagination-item", $e).on(pageTrigger,function(){ _this._stop(); _this.showIndex($(this).index(), pageEffect); }); } if($o.controls.active){ var opt = { active: true, target: ".control-handle", trigger: false, effect: false }; $.each($o.controls.handles,function(handle, option){ var $h = $.extend(true,{},opt,option), hTrigger, hEffect; hTrigger = $h.trigger ? $h.trigger : $o.trigger; hEffect = $h.effect ? $h.effect : $o.effect; $($h.target, $e).each(function(i, e) { $(e).show().addClass(handle + "-" + i); }).wrapAll('
'); if(!$h.active){ $($h.target, $e).hide(); } $($h.target, $e).on(hTrigger, function(){ _this._stop(); _this.showIndex($(this).index(), hEffect); }); }); } $e.fadeIn(500); $(".slides-slide", $e).eq($.data(this, "current")).css({ zIndex: 10, display: "block" }); this.setActive($.data(this, "current")); if($o.responsive){ _this.setSize(); $(window).resize(function(){ _this.setSize(); }); } if($o.keyboard.active){ var keyEffect = $o.keyboard.effect ? $o.keyboard.effect : $o.effect; $(window).keyup(function(e){ if(e.which == 37 || e.which == 109){ _this._stop(); _this.showIndex(_this._prev(), keyEffect); } if(e.which == 39 || e.which == 107){ _this._stop(); _this.showIndex(_this._next(), keyEffect); } }); } if($o.mousewheel.active && $.fn.mousewheel){ var wheelEffect = $o.mousewheel.effect ? $o.mousewheel.effect : $o.effect; $e.mousewheel(function(event, delta){ event.preventDefault(); _this._stop(); if(delta > 0){ _this.showIndex(_this._prev(), wheelEffect); } if(delta < 0){ _this.showIndex(_this._next(), wheelEffect); } }); } if($o.touch.active && typeof TouchEvent !== "undefined"){ $(".slides-container", $e).on("touchstart",function(e){ _this._stop(); _this.touchStart(e); }); $(".slides-container", $e).on("touchmove",function(e){ _this.touchMove(e); }); $(".slides-container", $e).on("touchend",function(e){ _this.touchEnd(e); }); } if($o.autoplay){ if($o.autoplay.timer.active){ if($($o.autoplay.timer.target, $e).length == 0){ $('
').wrapInner('
').appendTo($e); }else{ $($o.autoplay.timer.target, $e).addClass("slides-timer").wrapInner('
'); } } if($o.autoplay.player.active){ var playTrigger, playEffect, stopTrigger; if($($o.autoplay.player.play.target, $e).length == 0){ $("", { title: $o.autoplay.player.play.title, "class": "player-play player-button" }).wrapInner(''+$o.autoplay.player.play.text+'').appendTo($e); }else{ $($o.autoplay.player.play.target, $e).addClass("player-play player-button"); } if($($o.autoplay.player.stop.target, $e).length == 0){ $("", { title: $o.autoplay.player.stop.title, "class": "player-stop player-button" }).wrapInner(''+$o.autoplay.player.stop.text+'').appendTo($e); }else{ $($o.autoplay.player.play.target, $e).addClass("player-stop player-button"); } $(".player-button", $e).wrapAll('
'); playEffect = $o.autoplay.effect ? $o.autoplay.effect : $o.effect; playTrigger = $o.autoplay.player.play.trigger ? $o.autoplay.player.play.trigger : $o.trigger; stopTrigger = $o.autoplay.player.stop.trigger ? $o.autoplay.player.stop.trigger : $o.trigger; $(".player-play", $e).on(playTrigger,function(){ return _this._autoplay(true); }); $(".player-stop", $e).on(stopTrigger,function(){ return _this._autoplay(false); }); } if($o.autoplay.hoverPause){ $(".slides-container", $e).hover(function(){ _this._stop(); },function(){ _this._play(); }); } if($o.autoplay.autostart){ this._autoplay(true); } } return this.settings.callback.loaded($o.start, $e); }; /* *setSize函数,根据父级容器修改内容尺寸 */ Plugin.prototype.setSize = function(){ var _this = this,$e = this.element, $o = this.settings, width, height, current = $.data(this, "current"); width = $($e).parent().width(); width = width < $o.width ? width : $o.width; height = width * ($o.height / $o.width); $(".slides-container", $e).css({ width: width + 'px', height: height + 'px' }); $($e).css("width", width + 'px'); $.data(this, "size", {width: width, height: height}); }; /* *autoPlay */ Plugin.prototype._autoplay = function(s){ if(s){ $.data(this,"autoplay", true); $(".slides-player", this.element).addClass("slides-autoplay"); return this._play(); } if(!s){ $.data(this,"autoplay", false); $(".slides-player", this.element).removeClass("slides-autoplay"); return this._stop(); } } /* *play播放 */ Plugin.prototype._play = function(){ var _this = this, $e = this.element, $o = this.settings, autoEffect; autoEffect = $o.autoplay.effect ? $o.autoplay.effect : $o.effect; if(!$.data(_this, "playing") && $.data(this, "autoplay")){ this.timer($o.autoplay.interval,$(".slides-timer", $e)); $.data(this,"interval",setInterval(function(){ _this.timer($o.autoplay.interval,$(".slides-timer", $e)); _this.showIndex(_this._next(), autoEffect); },$o.autoplay.interval)); } $.data(this, "playing", true); $(".slides-player", $e).addClass("slides-playing"); } /* *pause暂停播放 */ Plugin.prototype._stop = function(){ $(".slides-timer", this.element).stop(true,true).find("*").stop(true,true); clearTimeout($.data(this,"interval")); $.data(this, "playing", false); $(".slides-player", this.element).removeClass("slides-playing"); } /* *timer计时器 */ Plugin.prototype.timer = function(interval,target){ var $e = this.element, $o = this.settings; if($o.autoplay.timer.active){ if($o.autoplay.timer.action.active){ return $o.autoplay.timer.action.actionFn(interval,target); }else{ $(".slides-timer", $e).children(".timer-cycle").stop(true,true).animate({width:"100%"},interval, "linear", function(){ $(this).css("width",0); }); } } } /* *TouchStart */ Plugin.prototype.touchStart = function(e){ var $e = this.element, touch = e.originalEvent.touches[0], current = $.data(this, "current"); $.data(this, "touchstart", {X: touch.pageX, Y: touch.pageY}); $.data(this, "touchtimer", Number(new Date())); this.resetAni(); $(".slides-slide", $e).eq(current).css({ display: "block", zIndex: 10 }); return e.stopPropagation(); } /* *TouchMove */ Plugin.prototype.touchMove = function(e){ var $e = this.element, touch = e.originalEvent.touches[0], current = $.data(this, "current"), touchstartX = $.data(this,"touchstart").X, touchstartY = $.data(this,"touchstart").Y, deltaX = touch.pageX - touchstartX, deltaY = touch.pageY - touchstartY, width = $.data(this, "size").width, next = this._next(), prev = this._prev(); if(Math.abs(deltaX) > Math.abs(deltaY)){ e.preventDefault(); $(".slides-slide", $e).eq(current).css("left",deltaX+"px"); if(deltaX>0){ $(".slides-slide", $e).eq(prev).css({ display: "block", zIndex: 9, left: (deltaX-width)+"px" }); }else{ $(".slides-slide", $e).eq(next).css({ display: "block", zIndex: 9, left: (deltaX+width)+"px" }); } } return e.stopPropagation(); } /* *TouchEnd */ Plugin.prototype.touchEnd = function(e){ var _this = this, $e = this.element, $o = this.settings, current = $.data(this, "current"), width = $.data(this, "size").width, speed, slideCurrent, prev, slidePrev, next, slideNext; prev = this._prev(); next = this._next(); slideCurrent = $(".slides-slide", $e).eq(current); slidePrev = $(".slides-slide", $e).eq(prev); slideNext = $(".slides-slide", $e).eq(next); deltaTime = Number(new Date()) - $.data(this, "touchtimer"); speed = $o.speed ? $o.speed : $o.touch.speed; var left = slideCurrent.position().left; if(left > width*0.5 || (left > width*0.1 && deltaTime < 200)){ this.setActive(prev); $o.callback.begin(current, prev, $e); $.data(this, "current", prev); slideCurrent.stop(false,true).animate({left: width+'px'}, speed*(1-left/width),function(){ $(this).css({ display: "none", zIndex: 0 }); }); slidePrev.stop(false,true).animate({left: "0%"}, speed*(1-left/width),function(){ $(this).css({ zIndex: 10 }); return $o.callback.complete(prev,$e); }); }else if(left < -width*0.5 || (left < -width*0.1 && deltaTime < 200)){ this.setActive(next); $o.callback.begin(current, next, $e); $.data(this, "current", next); slideCurrent.stop(false,true).animate({left: -width+'px'}, speed*(1+left/width), function(){ $(this).css({ display: "none", zIndex: 0 }); }); slideNext.stop(false,true).animate({left: "0%"}, speed*(1+left/width), function(){ $(this).css({ zIndex: 10 }); return $o.callback.complete(next, $e); }); }else{ slideCurrent.stop(true,false).animate({left: "0%"}, speed*Math.abs(left/width)); slidePrev.stop(true,false).animate({left: -width+'px'}, speed*Math.abs(left/width),function(){ $(this).css({ display: "none", zIndex: 0 }); }); slideNext.stop(true,false).animate({left: width+'px'}, speed*Math.abs(left/width),function(){ $(this).css({ display: "none", zIndex: 0 }); }); } if($.data(this, "autoplay") && !$.data(this, "playing")){ this._play(); } return e.stopPropagation(); } /* *resetAni,动画复位 */ Plugin.prototype.resetAni = function(){ $(".slides-grids",this.element).remove(); $('.slides-slide:not(:eq('+$.data(this,"current")+'))', this.element).stop(true,true).css({ display: "none", zIndex: 0, left: "0%", top: "0%", opacity: 1 }); } /* *show效果函数,即显 */ Plugin.prototype.show = function(current, index){ $(".slides-slide", this.element).eq(index).css({ display: "block", zIndex: 10 }); return this.settings.callback.complete(index,this.element); }; /* *slide效果函数,滑动 */ Plugin.prototype.slide = function(current, index){ var $e = this.element, $o = this.settings, len = $.data(this, "total") - 1, speed, easing, direction, posFrom, posTo; speed = $o.effects.slide.speed ? $o.effects.slide.speed : $o.speed; easing = $o.effects.slide.easing ? $o.effects.slide.easing : $o.easing; direction = $o.effects.slide.direction; var directions = ["leftRight","upDown"]; if(current < index){ posFrom = "100%"; posTo = "-100%"; } if(current > index){ posFrom = "-100%"; posTo = "100%"; } if(current == len && index == 0){ posFrom = "100%"; posTo = "-100%"; } if(current == 0 && index == len){ posFrom = "-100%"; posTo = "100%"; } $(".slides-slide", $e).eq(current).css({ display: "block", zIndex: 10 }).end().eq(index).css("z-index",10); var method = []; method[directions[0]] = function(){ $(".slides-slide", $e).eq(index).css({ display: "block", left: posFrom }); $(".slides-slide", $e).eq(index).stop(true,false).animate({ left: "0%" },speed,easing); $(".slides-slide", $e).eq(current).stop(true,true).animate({ left: posTo },speed,easing,function(){ $(this).css({ display: "none", zIndex: 0 }); return $o.callback.complete(index, $e); }); }; method[directions[1]] = function(){ $(".slides-slide", $e).eq(index).css({ display: "block", zIndex: 10, top: posFrom }); $(".slides-slide", $e).eq(index).stop(true,false).animate({ top: "0%" },speed,easing,function(){ return $o.callback.complete(index, $e); }); $(".slides-slide", $e).eq(current).stop(true,true).animate({ top: posTo },speed,easing,function(){ $(this).css({ display: "none", zIndex: 0 }); return $o.callback.complete(index, $e); }); }; if($.inArray(direction,directions) == -1){ direction = tools.randArr(directions); } method[direction](); } /* *fade效果函数,淡入 */ Plugin.prototype.fade = function(current, index){ var $e = this.element, $o = this.settings, speed, easing, crossfade; speed = $o.effects.fade.speed ? $o.effects.fade.speed : $o.speed; easing = $o.effects.fade.easing ? $o.effects.fade.easing : $o.easing; crossfade = typeof $o.effects.fade.crossfade == "boolean" ? $o.effects.fade.crossfade : tools.randArr([false,true]); $(".slides-slide", $e).eq(current).css({ display: "block", zIndex: 10 }).end().eq(index).css("z-index",10); if(crossfade){ $(".slides-slide", $e).eq(current).stop(false,true).fadeOut(speed, easing, function(){ $(this).css("z-index",0); }); $(".slides-slide", $e).eq(index).stop(false,true).fadeIn(speed, easing, function(){ return $o.callback.complete(index, $e); }); }else{ $(".slides-slide", $e).eq(current).stop(false,true).fadeOut(speed*0.5, easing, function(){ $(this).css("z-index",0); $(".slides-slide", $e).eq(index).stop(false,true).fadeIn(speed*0.5, easing, function(){ return $o.callback.complete(index, $e); }); }); } }; /* *drift效果函数,漂移 */ Plugin.prototype.drift = function(current, index){ var $e = this.element, $o = this.settings, speed, easing, direction, dis, _dis, opacity, left = 0, top = 0; speed = $o.effects.drift.speed ? $o.effects.drift.speed : $o.speed; easing = $o.effects.drift.easing ? $o.effects.drift.easing : $o.easing; direction = $o.effects.drift.direction; var directions = ["left","right","top","bottom","leftTop","leftBottom","rightTop","rightBottom"]; if($.inArray(direction,directions) == -1){ direction = tools.randArr(directions); } dis = "100%", _dis = "-100%", opacity = 1; if($o.effects.drift.fadeout){ opacity = typeof $o.effects.drift.fadeout == "boolean" ? 0 : tools.randArr([0,1]); } if(opacity==0){ dis = "70%", _dis = "-70%"; } left = /left/i.test(direction) ? _dis : 0; left = /right/i.test(direction) ? dis : left; top = /top/i.test(direction) ? _dis : 0; top = /bottom/i.test(direction) ? dis : top; $(".slides-slide", $e).eq(current).css({ display: "block", zIndex: 10 }).end().eq(index).css({ display: "block", zIndex: 9 }); $(".slides-slide", $e).eq(current).stop(true,true).animate({ left:left, top: top, opacity: opacity },speed,easing,function(){ $(".slides-container", $e).css("overflow","hidden"); $(this).css({ display: "none", zIndex: 0 }); $(".slides-slide", $e).eq(index).css("z-index",10); return $o.callback.complete(index,$e); }); }; /* *grids随机栅格效果函数 */ Plugin.prototype.grids = function(current, index){ var _this = this, $e = this.element, $o = this.settings, cols = $o.effects.grids.isRandom ? tools.sortNum($o.effects.grids.cols, 0)[0] : $o.effects.grids.cols, rows = $o.effects.grids.isRandom ? tools.sortNum($o.effects.grids.rows, 0)[0] : $o.effects.grids.rows, cells = cols*rows, speed = $o.effects.grids.speed ? $o.effects.grids.speed : $o.speed, easing = $o.effects.grids.easing ? $o.effects.grids.easing : $o.easing, sWidth = $.data(this,"size").width, sHeight = $.data(this,"size").height, width = Math.ceil(sWidth/cols), height = Math.ceil(sHeight/rows) lWidth = sWidth-width*(cols-1), lHeight = sHeight-height*(rows-1); $("
").appendTo(".slides-container", $e).css({ width: sWidth+'px', height: sHeight+'px', position: "absolute", left:0, top:0, zIndex: 20 }); $.each(new Array(cells),function(i,e){ var row = Math.ceil((i+1)/cols)-1, col = i-row*cols; var gWidth = col+1 == cols ? lWidth: width; var gHeight = row+1 == rows ? lHeight : height; $('
').prependTo(".slides-grids", $e).css({ width:gWidth+'px', height:gHeight+'px', overflow:"hidden", position:"absolute", zIndex:15, top:row*height+'px', left:col*width+'px' }).html($(".slides-slide",$e).eq(current).clone().html()) .wrapInner('
'); $('
').prependTo(".slides-grids", $e).css({ display:"none", width:gWidth+'px', height:gHeight+'px', overflow:"hidden", position:"absolute", zIndex:12, top:row*height+'px', left:col*width+'px' }).html($(".slides-slide",$e).eq(index).clone().html()) .wrapInner('
'); }); var gIndex = tools.randArr([1,-1,0]); if(cols>1&&rows>1){ gIndex = 0; } var outCss = $o.effects.grids.outCss, aniCss = [], cssWidth = {width:0}, cssHeight = {height:0}, cssOpacity = {opacity:0}; if(/width/gi.test(outCss)){ aniCss.push(cssWidth); } if(/height/gi.test(outCss)){ aniCss.push(cssHeight); } if(/opacity/gi.test(outCss)){ aniCss.push(cssOpacity); } var animation = {}, ani = [], randSort = tools.sortNum(aniCss.length,0), randNum = tools.randArr(randSort), outSpeed; if($o.effects.grids.autoGroup){ $.each(randSort,function(i,e){ if(i < randNum){ ani[i] = aniCss[e-1]; } }); }else{ ani = aniCss; } $.each(ani,function(i,e){ animation = $.extend(true,{},animation,e); }); if($o.effects.grids.flash){ outSpeed = 0; }else{ outSpeed = speed/2; } $.each(tools.sortNum(cells, gIndex),function(i,e) { setTimeout(function(){ $(".slide-grid-index", $e).eq(e-1).fadeIn(speed/2,easing); $(".slide-grid-current", $e).eq(e-1).animate(animation,outSpeed,easing); },i*speed/cells); if(i== cells-1 ){ return $o.callback.complete(index, $e) } }); } /* *注册需要调用的效果函数 */ Plugin.prototype.limitEffects = function(){ var allEffects = ["show","slide","fade","drift","grids"]; // 所有支持的效果函数 var useEffects = []; if(this.settings.limitEffects){ $.each(this.settings.limitEffects.split(","),function(i, e){ e = $.trim(e); if($.inArray(e, allEffects) !== -1){ useEffects.push(e); } }); } return useEffects.length > 0 ? useEffects : allEffects; } /* *transEffect函数,调用效果函数 */ Plugin.prototype.transEffect = function(current, index, effect){ switch (effect){ case "show" : this.show(current, index); break; case "slide" : this.slide(current, index); break; case "fade" : this.fade(current, index); break; case "drift" : this.drift(current, index); break; case "grids" : this.grids(current, index); break; }; }; /* * 设置当前活动状态的组件 */ Plugin.prototype.setActive = function(number){ var $e = this.element, $o = this.settings; $(".active", $e).removeClass("active"); $(".pagination-item", $e).eq(number).addClass("active"); $(".slides-control", $e).each(function() { $(this).children().eq(number).addClass("active"); }); if($.data(this,"slidesTitle")[number].length > 0){ // 重置当前的数值 if(number==2){ var n = 0; }else{ n = number+1; } $(".slide-title", $e).show().html($.data(this,"slidesTitle")[number]).wrapInner("

"); //$(".slide-title1", $e).show().html($.data(this,"slidesTitle")[n]).wrapInner("

"); //插入下一组信息 //$(".slide-intro1", $e).show().html($.data(this,"slidesIntro1")[n]).wrapInner("

"); //插入下一组信息 //$(".show1", $e).show().html('0'+$.data(this,"slidesNum")[number]+'/ 3').wrapInner("

"); //$(".show1", $e).show().html($.data(this,"slidesNum")[number]).addClass(""+number+""); //$(".show2", $e).show().html($.data(this,"slidesNum")[n]).wrapInner("

"); //console.log($.data(this,"slidesNum")[number]); }else{ $(".slide-title", $e).hide().empty(); } //window.console&&console.log(this._next()+"====="+ this._prev()); if($.data(this,"slidesIntro")[number].length > 0){ $(".slide-intro", $e).show().html($.data(this,"slidesIntro")[number]).wrapInner("

"); }else{ $(".slide-intro", $e).hide().empty(); } }; /* * showIndex函数 */ Plugin.prototype.showIndex = function(index, effect){ var current = $.data(this, "current"), effects = $.data(this, "effects"); if($.inArray(effect, effects) == -1){ effect = tools.randArr(effects); } if($.data(this, "autoplay")){ this._play(); } if(current !== index){ this.resetAni(); this.setActive(index); this.settings.callback.begin(current, index, this.element); $.data(this, "current", index); this.transEffect(current, index, effect); } }; /* * _prev函数 */ Plugin.prototype._prev = function(){ var index = $.data(this, "current") - 1; if(index < 0){ index = $.data(this, "total") - 1; } return index; }; /* * _next函数 */ Plugin.prototype._next = function(){ var index = $.data(this, "current") + 1; if(index > $.data(this, "total") - 1){ index = 0; } return index; }; /* *插件辅助tools */ var tools = { isIE6 : function(){ return !-[1,]&&!window.XMLHttpRequest; }, randArr: function(arr){ var key = Math.floor(Math.random()*arr.length); return arr[key]; }, sortNum: function(count, order){ var original = new Array; for (var i=0;i