/** * @author 愚人码头 */ (function($){ $.fn.slide=function(options){ var opts = $.extend({}, $.fn.slide.deflunt, options); var that = $(this); var index=1; var targetli = $("." + opts.clanav + " li", $(this));//目标对象 var clicknext = $("." + opts.clanav + " .next", $(this));//点击下一个按钮 var clickprev = $("." + opts.clanav + " .prev", $(this));//点击上一个按钮 var contentbox = $("." + opts.clacon , $(this));//滚动的对象 var contentboxnum=contentbox.children().size();//滚动对象的子元素个数 var slideh=contentbox.children().first().height();//滚动对象的子元素个数高度,相当于滚动的高度 var slidew=contentbox.children().first().width();//滚动对象的子元素宽度,相当于滚动的宽度 var autoy; var slidewh; var action = opts.effect; if(opts.effect=="scrooly"||opts.effect=="scrooltxt"){ slidewh=slideh; }else if(opts.effect=="scroolx"||opts.effect=="scroolloop"){ contentbox.css("width",contentboxnum*slidew); slidewh=slidew; }else if(opts.effect=="fade"){ contentbox.children().first().css("z-index","1"); } return this.each(function() { var $this=$(this); //滚动函数 var doplay=function(){ $.fn.slide.effect[opts.effect](contentbox, targetli, index, slidewh, opts.speed); index++; if (index*opts.steps >= contentboxnum) { index = 0; } }; clicknext.click(function(event){ $.fn.slide.effectloop.scroolleft(contentbox, targetli, index, slidewh, opts,function(){ for(var i=0;i= contentboxnum ? 0 : index; }; if (opts.autoplay) { fadeaotu(0); autoy = setinterval(fadeaotu, opts.timer); that.hover(function () { if (opts.autoplay) { autoy = clearinterval(autoy); } }, function () { if (opts.autoplay) { autoy = setinterval(fadeaotu, opts.timer); } }); }; function slide(i) { contentbox.children().eq(i).stop().animate({ opacity: 1, "z-index": "1" }, 500).siblings().stop().animate({ opacity: 0, "z-index": "0" }, 500); targetli.eq(i).addclass("on").siblings().removeclass("on"); }; //目标事件 var d = new date(); var s = d.gettime(); targetli.hover(function(){ if (opts.autoplay) { autoy = clearinterval(autoy); }; var d = new date(); var ed = d.gettime() - s; if (ed >= 350) { index = targetli.index(this); window.settimeout(function () { $.fn.slide.effect[opts.effect](contentbox, targetli, index, slidewh, opts); }, 200); } else { s = d.gettime(); return false; }; },function(){ /*if(opts.autoplay){ autoy = setinterval(doplay, opts.timer); } */ s = d.gettime() }); }); }; $.fn.slide.deflunt={ effect : "scrooly", autoplay:true, speed : "normal", timer : 1000, defindex : 0, clanav:"jq-slide-nav", clacon:"jq-slide-content", steps:1 }; $.fn.slide.effectloop={ scroolleft:function(contentobj,navobj,i,slidew,opts,callback){ contentobj.animate({"left":-i*opts.steps*slidew},opts.speed,callback); if (navobj) { navobj.eq(i).addclass("on").siblings().removeclass("on"); } }, scroolright:function(contentobj,navobj,i,slidew,opts,callback){ contentobj.stop().animate({"left":0},opts.speed,callback); } } $.fn.slide.effect={ fade: function (contentobj, navobj, i, slidew, speed) { //console.log(i); contentobj.children().eq(i).stop().animate({opacity:1},speed).css({"z-index": "1"}).siblings().animate({opacity: 0},speed).css({"z-index":"0"}); navobj.eq(i).addclass("on").siblings().removeclass("on"); }, scrooltxt:function(contentobj,undefined,i,slideh,opts){ //alert(i*opts.steps*slideh); contentobj.animate({"margin-top":-opts.steps*slideh},speed,function(){ for( var j=0;j