/*! * jquery cxscroll 1.2.1 * jquery cxscroll 间歇式无缝滚动 * =============================================================================== * 参数说明 * 名称 默认值 说明 * direction 'right' 滚动方向。可设置为:"left", "right", "top", "bottom" * easing 'swing' 缓动方式 * step 1 滚动步长 * accel 160 手动滚动速度 (ms),点击控制按钮滚动的速度。 * speed 800 自动滚动速度 (ms) * time 4000 自动滚动间隔时间 (ms) * auto true 是否自动滚动 * prevbtn true 是否使用 prev 按钮 * nextbtn true 是否使用 next 按钮 * safelock true 滚动时是否锁定控制按钮 * =============================================================================== * html code *
* =============================================================================== * javascript code * $('#element_id').cxscroll(); * =============================================================================== * 示例 * \demo\cxscroll\cxscroll.html */ !function(a){a.fn.cxscroll=function(b){var c,d;this.length&&(b=a.extend({},a.cxscroll.defaults,b),c=this,d={lock:!1,dom:{}},d.init=function(){if(d.dom.box=c.find(".box"),d.dom.list=d.dom.box.find(".list"),d.dom.items=d.dom.list.find("li"),d.itemsum=d.dom.items.length,!(d.itemsum<=1)){if(d.dom.prevbtn=c.find(".prev"),d.dom.nextbtn=c.find(".next"),d.itemwidth=d.dom.items.outerwidth(),d.itemheight=d.dom.items.outerheight(),"left"==b.direction||"right"==b.direction){if(d.itemwidth*d.itemsum<=d.dom.box.outerwidth())return;d.prevval="left",d.nextval="right",d.moveval=d.itemwidth}else{if(d.itemheight*d.itemsum<=d.dom.box.outerheight())return;d.prevval="top",d.nextval="bottom",d.moveval=d.itemheight}d.dom.list.append(d.dom.list.html()),b.prevbtn&&!d.dom.prevbtn.length&&(d.dom.prevbtn=a("",{"class":"prev"}).prependto(c)),b.nextbtn&&!d.dom.nextbtn.length&&(d.dom.nextbtn=a("",{"class":"next"}).prependto(c)),b.auto&&c.hover(function(){b.auto=!1,d.lock=!1,d.off()},function(){b.auto=!0,d.lock=!1,d.on()}),d.bindevents(),d.on()}},d.bindevents=function(){b.nextbtn&&d.dom.prevbtn.length&&d.dom.nextbtn.bind("click",function(){d.lock||d.goto(d.nextval,b.accel)}),b.prevbtn&&d.dom.prevbtn.length&&d.dom.prevbtn.bind("click",function(){d.lock||d.goto(d.prevval,b.accel)})},d.on=function(){b.auto&&("undefined"!=typeof d.run&&cleartimeout(d.run),d.run=settimeout(function(){d.goto(b.direction)},b.time))},d.off=function(){d.dom.box.stop(!0),"undefined"!=typeof d.run&&cleartimeout(d.run)},d.goto=function(c,e){var f,g,h;switch(d.off(),b.controllock&&(d.lock=!0),h=e||b.speed,c){case"left":case"top":f=0,"left"==c?(0==parseint(d.dom.box.scrollleft(),10)&&d.dom.box.scrollleft(d.itemsum*d.moveval),g=d.dom.box.scrollleft()-d.moveval*b.step,g%d.itemwidth>0&&(g-=g%d.itemwidth-d.itemwidth),f>g&&(g=f),d.dom.box.animate({scrollleft:g},h,b.easing,function(){parseint(d.dom.box.scrollleft(),10)<=f&&d.dom.box.scrollleft(0)})):(0==parseint(d.dom.box.scrolltop(),10)&&d.dom.box.scrolltop(d.itemsum*d.moveval),g=d.dom.box.scrolltop()-d.moveval*b.step,g%d.itemheight>0&&(g-=g%d.itemheight-d.itemheight),f>g&&(g=f),d.dom.box.animate({scrolltop:g},h,b.easing,function(){parseint(d.dom.box.scrolltop(),10)<=f&&d.dom.box.scrolltop(0)}));break;case"right":case"bottom":f=d.itemsum*d.moveval,"right"==c?(g=d.dom.box.scrollleft()+d.moveval*b.step,g%d.itemwidth>0&&(g-=g%d.itemwidth),g>f&&(g=f),d.dom.box.animate({scrollleft:g},h,b.easing,function(){parseint(d.dom.box.scrollleft(),10)>=f&&d.dom.box.scrollleft(0)})):(g=d.dom.box.scrolltop()+d.moveval*b.step,g%d.itemheight>0&&(g-=g%d.itemheight),g>f&&(g=f),d.dom.box.animate({scrolltop:g},h,b.easing,function(){parseint(d.dom.box.scrolltop(),10)>=f&&d.dom.box.scrolltop(0)}))}d.dom.box.queue(function(){b.controllock&&(d.lock=!1),d.on(),a(this).dequeue()})},d.init())},a.cxscroll={defaults:{direction:"right",easing:"swing",step:1,accel:160,speed:800,time:4e3,auto:!0,prevbtn:!0,nextbtn:!0,safelock:!0}}}(jquery);