/** * @classdescription 模拟marquee,无间断滚动内容 * @author aken li(www.kxbd.com) * @dom *
* *
* @css * #marquee {overflow:hidden;width:200px;height:50px;} * @usage * $("#marquee").kxbdmarquee(options); * @options * isequal:true, //所有滚动的元素长宽是否相等,true,false * loop:0, //循环滚动次数,0时无限 * direction:"left", //滚动方向,"left","right","up","down" * scrollamount:1, //步长 * scrolldelay:20 //时长 */ !function(a){a.fn.kxbdmarquee=function(b){var c=a.extend({},a.fn.kxbdmarquee.defaults,b);return this.each(function(){function l(){var b,a="left"==c.direction||"right"==c.direction?"scrollleft":"scrolltop";return c.loop>0&&(k+=c.scrollamount,k>i*c.loop)?(d[a]=0,clearinterval(m)):("left"==c.direction||"up"==c.direction?(b=d[a]+c.scrollamount,b>=i&&(b-=i),d[a]=b):(b=d[a]-c.scrollamount,0>=b&&(b+=i),d[a]=b),void 0)}var k,m,b=a(this),d=b.get(0),e=b.width(),f=b.height(),g=b.children(),h=g.children(),i=0,j="left"==c.direction||"right"==c.direction?1:0;g.css(j?"width":"height",1e4),c.isequal?i=h[j?"outerwidth":"outerheight"]()*h.length:h.each(function(){i+=a(this)[j?"outerwidth":"outerheight"]()}),(j?e:f)>i||(g.append(h.clone()).css(j?"width":"height",2*i),k=0,m=setinterval(l,c.scrolldelay),b.hover(function(){clearinterval(m)},function(){clearinterval(m),m=setinterval(l,c.scrolldelay)}))})},a.fn.kxbdmarquee.defaults={isequal:!0,loop:0,direction:"left",scrollamount:1,scrolldelay:20},a.fn.kxbdmarquee.setdefaults=function(b){a.extend(a.fn.kxbdmarquee.defaults,b)}}(jquery);