6

我需要一个用于个人项目的自定义滚动条插件(“自定义”是指基本惯性效果、自定义图像等)。我的选择是mCustomScrollbar

文档确实很清楚,我在实现脚本时没有遇到任何问题,但它似乎只有在我调整页面大小时才有效,好像不需要滚动一样。

事实上,滚动条style="display: hidden"在一个完全加载的页面上,就像在这个问题中一样(但我找不到任何有用的答案)。

我相信有一些height问题与slidesjs(我也在使用)相关,但我找不到它......这里有一些代码:

整页,所以你可以用firebug查看代码......只需进入“Pulcini”查看长内容)

<head>
  <!-- everything is included -->
  <link href="css/style.css" type="text/css" rel="stylesheet" />
  <link href="css/jquery.mCustomScrollbar.css" type="text/css" rel="stylesheet" />
  <script type="text/javascript" src="js/jquery.mousewheel.min.js"></script>
  <script type="text/javascript" src="js/jquery.mCustomScrollbar.js"></script>
  <script>
    $(function(){
      $("#slides").slides({
        generatePagination: false,
        pagination: true,
        paginationClass: 'pagination'
      });
    });
  </script>
  <script>
    (function($){
      $(window).load(function(){
        $("#slide2").mCustomScrollbar();
      });
    })(jQuery);
  </script>
</head>
<body>
  <div id="slides">
    <!-- other stuff -->
    <div class="slides_container">
      <div id="slide1">
        <h2>Uova</h2>
        <p>Text1...</p>
      </div>
      <!-- slide2 is the scrollbar div -->
      <div id="slide2">
        <h2>Blabla</h2>
        <p>Lorem ipsum</p><br />
      </div>
    </div>
  </div>
</body>

CSS:

div#slides {
  height: 506px;
}
.slides_container {
  width: 900px;
  height: 506px;
}

.slides_container, div#slide1, div#slide2, div#slide3, {
  width: 808px;
  height: 366px;
  display: block;
  float: left;
  overflow-y: auto;
}

.slides_container {
  margin-top: 30px;
  margin-bottom: 30px;
  height: 366px;
}​
4

3 回答 3

16

我有同样的问题。updateOnBrowserResize: true所以我更改了, 和 的流体代码updateOnContentResize: true,现在它适用于所有 javascript。

(function($) {  
  $(window).load(function() {  
    $("#content_1").mCustomScrollbar({  
      scrollEasing:"easeOutCirc",  
      mouseWheel:"auto",   
      autoDraggerLength:true,   
      advanced:{  
        updateOnBrowserResize:true,   
        updateOnContentResize:true   
      } // removed extra commas  
    });  
  });  
})(jQuery);
于 2012-09-11T05:42:03.113 回答
3

您正在初始化 mCustomScrollbar 而其所在的容器仍处于隐藏状态,因此浏览器无法计算 div 的高度。您需要在 div 可见时触发 resize 事件,或者在滚动条第一次在页面上变为活动状态之前不要初始化滚动条。

于 2012-09-11T02:32:42.613 回答
0

http://manos.malihu.gr/jquery-custom-content-scroller/

这是自定义滚动条的非常好的链接我也在我的项目中使用了这个插件,你可以轻松地自定义它,嵌套滚动条也可以在这里使用。

于 2013-07-24T12:39:44.520 回答