瀏覽代碼

自定义滚动条

zhangxc 5 年之前
父節點
當前提交
532f41cbc2
共有 1 個文件被更改,包括 15 次插入4 次删除
  1. 15 4
      src/js/scrollBar.js

+ 15 - 4
src/js/scrollBar.js

@@ -64,9 +64,12 @@
       var sliderHeight;
       if(this.$scrollDir == "Y"){
         rate = this.$cont.height() /this.$cont[0].scrollHeight;
-        this.$bar.css({
-          "top": "0px"
-        })
+        if(!this.$bar.css("top")){
+          this.$bar.css({
+            "top": "0px"
+          })
+        }
+        
         sliderHeight = rate*this.$bar.height();
         this.$slider.css('height',sliderHeight);
       }else{
@@ -75,7 +78,7 @@
           "width": "100%",
           "height": "5px",
           "bottom": "0px",
-          "zIndex": "100"
+          "zIndex": "100",
         })
         this.$slider.css({
           "height":"5px"
@@ -140,7 +143,14 @@
           doc.on('mousemove.scroll', mousemoveHandler).on('mouseup.scroll',function(){
             doc.off('.scroll');
           });
+          self.$cont.on("mouseleave",function(e){
+            e.stopPropagation()
+            doc.off('.scroll');
+          })
         });
+        slider.on("click",function(e){
+          e.stopPropagation()
+        })
         this.$bar.on("click",function(e){
           var scrollHei 
           dragContBarRate = self.getMaxScrollPosition()/self.getMaxSliderPosition();
@@ -160,6 +170,7 @@
           }
           // dragStartScrollPostion = self.$cont[0].scrollTop;
         })
+        
         return self;
       }
     },