jQuery.fn.extend 用法

黄金清纯小王子 2018-01-11 10:55:21
;(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的原型,但是现在封装的时候不知道放在哪里了,希望大神指教
...全文
255 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

87,904

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧