為什么不能移動文檔內容
if(sliderEl){
? ? ? ?var doc = this.$doc,//獲取文本對象
? ? ? ?dragStartPagePosition,//鼠標起始位置
? ? ? ?dragStartScrollPosition,//元素內容的起始位置
? ? ? ?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();//去除文本對象默認功能
? ? ? ? ? ?console.log("mousedown");
? ? ? ? ? ?dragStartPagePosition = e.pageY;//獲取鼠標距離文檔頂部的距離
? ? ? ? ? ?alert('1'+self.$cont[0].scrollTop);
? ? ? ? ? ?dragStartScrollPosition = self.$cont[0].scrollTop;//滾動區內容對象的起始數據
? ? ? ? ? ?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;
},
//內容可滾動的高度
getMaxScrollPosition:function () {
? ? var self = this;
? ? //獲取滾動條內容高度:可視區和元素內容高度的最大值
? ? return Math.max(self.$cont.height(),self.$cont[0].scrollHeight)-self.$cont.height();
? ? //內容可滾動的距離為:文本內容高度-可視區內容高度,當文本內容高度小于可視區時可移動距離為0
},
//滑塊可移動的高度
getMaxSliderPosition:function () {
? ?var self = this;
? ?return self.$bar.height() - self.$slider.height();//可移動的高度就是滾動條的高度-滑塊的高度
},
//滾動函數
scrollTo:function (positionVal) {
? ?var self = this;
? ?self.$cont.scrollTop(positionVal);//設置每個匹配元素的垂直滾動條位置,元素內容超出上邊界的像素
}