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的原型,但是现在封装的时候不知道放在哪里了,希望大神指教
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的原型,但是现在封装的时候不知道放在哪里了,希望大神指教
...全文
相关推荐
jQuery.extend 与 jQuery.fn.extend的用法及区别实例分析
主要介绍了jQuery.extend 与 jQuery.fn.extend的用法及区别,结合实例形式分析了jQuery.extend与jQuery.fn.extend的功能、使用方法及区别,需要的朋友可以参考下
jquery简单插件制作(fn.extend)完整实例
主要介绍了jquery简单插件制作(fn.extend)方法,结合完整实例形式分析了jQuery fn.extend扩展插件的实现技巧,需要的朋友可以参考下
jQuery的extend方法【三种】
jq中的extend在面试中经常会被问道,今天我总结一个下有关于extend的用法三种进行对比,可能不全,希望大家指点, 用法一: $.extend({}) ,为jQuery类添加方法,可以理解为扩展静态方法 用法二:$.fn.extend({}) 插件,对jQuery.prototype进行扩展,提到插件那么就得说一下另一种方法$.fn.method = function(){} 1. $.fn.method = function(){} 可以定义一个方法 2 . $.fn.extend({}) 定义多个方法。 需要实例化
jQuery中extend函数的实现原理详解
主要介绍了jQuery中extend函数的实现原理详解,extend()函数用于jQuery插件的开发,本文主要分析它的实现原理,需要的朋友可以参考下
jQuery继承extend用法详解
主要为大家详细介绍了jQuery继承extend用法,具有一定的参考价值,感兴趣的小伙伴们可以参考一下


