jQuery.fn.extend 用法
;(function($){
jQuery.fn.extend({
Scroll:function(){
var _this=this
var oScroll=$(this)
this.oScrollUl=oScroll.find('ul');
this.oScrollLi=oScroll.find('li');
this.speed=2;
this.oScrollUlW=(parseInt(this.oScrollLi.css('margin-left'))*2+this.oScrollLi.innerWidth()+parseInt(this.oScrollLi.css('border-left'))*2);
this.num=0;
this.timer=null;
this.oScrollUl.append(this.oScrollUl.html())
this.oScrollUl.width(this.oScrollUlW*this.oScrollLi.length*2);
this.oScrollLi.each(function(index,element){
this.num=$(element).index()
})
this.timer=setInterval(function(){
_this.oScr()
},30)
this.oScrollUl.mouseover(function(){
clearInterval(_this.timer)
})
this.oScrollUl.mouseout(function(){
_this.timer=setInterval(function(){
_this.oScr()
},30)
})
Scroll.prototype.oScr=function(){
this.oScrollUl.css({left:this.oScrollUl.position().left+this.speed})
if(this.oScrollUl.position().left<-this.oScrollUl.width()/2){
this.oScrollUl.css({left:0})
}
else if(this.oScrollUl.position().left>0){
this.oScrollUl.css({left:-this.oScrollUl.width()/2})
}
}
}
})
})(jQuery)
Scroll.prototype.oScr写的时候是 的Scroll的原型,但是现在封装的时候不知道放在哪里了,希望大神指教