為什么不能移動文檔內(nèi)容
if(sliderEl){
? ? ? ?var doc = this.$doc,//獲取文本對象
? ? ? ?dragStartPagePosition,//鼠標(biāo)起始位置
? ? ? ?dragStartScrollPosition,//元素內(nèi)容的起始位置
? ? ? ?dragContBarRate;//???
? ? ? ?function mousemoveHandler() {
? ? ? ? ? ?e.preventDefault();
? ? ? ? ? ?console.log("mousemove");
? ? ? ? ? ?if(dragStartPagePosition == null){
? ? ? ? ? ? ? ?return ;
? ? ? ? ? ?}
? ? ? ? ? ?self.scrollTo(dragStartScrollPosition + (e.pageY-dragStartPagePosition)*0.5);
? ? ? ?}
? ? ? ?slider.on("mousedown",function (e) {
? ? ? ? ? ?e.preventDefault();//去除文本對象默認(rèn)功能
? ? ? ? ? ?console.log("mousedown");
? ? ? ? ? ?dragStartPagePosition = e.pageY;//獲取鼠標(biāo)距離文檔頂部的距離
? ? ? ? ? ?alert('1'+self.$cont[0].scrollTop);
? ? ? ? ? ?dragStartScrollPosition = self.$cont[0].scrollTop;//滾動區(qū)內(nèi)容對象的起始數(shù)據(jù)
? ? ? ? ? ?alert('2');
? ? ? ? ? ?alert("dragStartPagePosition"+dragStartPagePosition+"dragStartScrollPosition"+dragStartScrollPosition)
? ? ? ? ? ?doc.on("mousemove.scroll", mousemoveHandler())
? ? ? ? ? ? ? ?.on("mouseup.scroll",function (e) {
? ? ? ? ? ? ? ? ? ?console.log("mouseup");
? ? ? ? ? ? ? ? ? ?doc.off(".scroll")
? ? ? ? ? ? ? ? ? ?});
? ? ? ?});
? ?}
? ?return self;
},
//內(nèi)容可滾動的高度
getMaxScrollPosition:function () {
? ? var self = this;
? ? //獲取滾動條內(nèi)容高度:可視區(qū)和元素內(nèi)容高度的最大值
? ? return Math.max(self.$cont.height(),self.$cont[0].scrollHeight)-self.$cont.height();
? ? //內(nèi)容可滾動的距離為:文本內(nèi)容高度-可視區(qū)內(nèi)容高度,當(dāng)文本內(nèi)容高度小于可視區(qū)時可移動距離為0
},
//滑塊可移動的高度
getMaxSliderPosition:function () {
? ?var self = this;
? ?return self.$bar.height() - self.$slider.height();//可移動的高度就是滾動條的高度-滑塊的高度
},
//滾動函數(shù)
scrollTo:function (positionVal) {
? ?var self = this;
? ?self.$cont.scrollTop(positionVal);//設(shè)置每個匹配元素的垂直滾動條位置,元素內(nèi)容超出上邊界的像素
}