知识点
- $.extend 方法
- jQuery 事件命名空间
- 事件对象属性 : pageX 、 pageY
- 获得原生事件 : e.originalEvent
- 位置方法 : scrollTop、scrollLeft、scrollHeight、scrollWidth 、position
- 滚轮事件的处理 :oEv.wheelDelta 、oEv.deltail
js
(function(win,doc,$){
function CusScrollBar(options){
this._init(options);
}
$.extend(CusScrollBar.prototype,{
_init:function(options){
var self=this;
self.options={
scrollDir :"y",
contSelector :"",
barSelector :"",
sliderSelector :"",
wheelStep :10,
tabItemSelector:"",
tabActiveClass :"",
anchorSelector :"",
correctSelector:"",
articalSelector:"",
isAnimate :false,
speed :800,
}
$.extend(true,self.options,options || {});
self._initDomEvent();
return self;
},
_initDomEvent:function(){
var opts=this.options;
this.$cont=$(opts.contSelector);
this.$slider=$(opts.sliderSelector);
this.$bar=opts.barSelector ? $(opts.barSelector) : self.$slider.parent();
this.$doc=$(doc);
this.$tabItem=$(opts.tabItemSelector);
this.$anchor=$(opts.anchorSelector);
this.$article=$(opts.articalSelector);
this.$correct=$(opts.correctSelector);
this._initSliderDragEvent()
._bindContScroll()
._bindMouseWheel()
._initTabEvent()
.initArticleHeight();
},
_initSliderDragEvent:function(self){
var slider=this.$slider,
sliderEl=slider[0],
self=this;
if(sliderEl){
var doc=this.$doc,
dragStratPagePosition,
dragStartScrollPosition,
dragContBarRate;
function mousemoveHandler (e){
e.preventDefault;
console.log("mousemove");
if(dragStratPagePositio