瀏覽代碼

自定义滚动条

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

+ 6 - 7
src/js/scrollBar.js

@@ -49,6 +49,7 @@ const $ = require("jquery");
       //滚动方向
       //滚动方向
       this.$scrollDir = opts.scrollDir || "Y"
       this.$scrollDir = opts.scrollDir || "Y"
       this.$sliderMode = opts.sliderMode || 1
       this.$sliderMode = opts.sliderMode || 1
+      this.$top = opts.top || "0px"
       // 获取文档对象
       // 获取文档对象
       this.$doc = $(doc);
       this.$doc = $(doc);
       // 获取初始化滑块拖动功能
       // 获取初始化滑块拖动功能
@@ -68,13 +69,9 @@ const $ = require("jquery");
       var sliderHeight;
       var sliderHeight;
       if(this.$scrollDir == "Y"){
       if(this.$scrollDir == "Y"){
         rate = this.$cont.height() /this.$cont[0].scrollHeight;
         rate = this.$cont.height() /this.$cont[0].scrollHeight;
-        console.log('top',this.$bar,this.$bar.css("top"))
-        if(!this.$bar.css("top")){
-          this.$bar.css({
-            "top": "0px"
-          })
-        }
-        
+        this.$bar.css({
+          "top": this.$top
+        })
         sliderHeight = rate*this.$bar.height();
         sliderHeight = rate*this.$bar.height();
         this.$slider.css('height',sliderHeight);
         this.$slider.css('height',sliderHeight);
       }else{
       }else{
@@ -99,6 +96,8 @@ const $ = require("jquery");
       }
       }
       if(rate === 1){
       if(rate === 1){
         this.$bar.css('display','none');
         this.$bar.css('display','none');
+      } else{
+        this.$bar.css('display','block');
       }
       }
       // this.$slider.css('height',sliderHeight);
       // this.$slider.css('height',sliderHeight);
      },
      },