原文地址:http://manos.malihu.gr/jquery-custom-content-scroller/
下载地址:/download/a707369808/10562825
引入css
<link rel="stylesheet" href="/path/to/jquery.mCustomScrollbar.css" />
引入js
<script src="/ajax/libs/jquery/1.11.1/jquery.min.js"></script><script src="/path/to/jquery.mCustomScrollbar.concat.min.js"></script>
要添加滚动条的元素应该具有溢出块的典型CSS属性,这些属性是高度(或最大高度)值,auto(或隐藏)的溢出值和足够长的内容需要滚动。对于水平滚动条,元素应设置宽度(或最大宽度)值。
如果您希望通过javascript设置元素的高度/宽度,则可以使用setHeight
/setWidth
option参数。
初始化
<script>(function($){$(window).on("load",function(){$(".content").mCustomScrollbar();//content为需要增加滚动条的class});})(jQuery);</script>
可以直接在您需要增加滚动条的容器增加class=“mCustomScrollbar
”,设置滚动条放向data-mcs-axis,值为x或y,设置主题data-mcs-theme
<div class="mCustomScrollbar" data-mcs-theme="dark"><!-- your content --></div>
默认情况下,脚本应用垂直滚动条。要添加水平或2轴滚动条,请在轴选项设置为"x"
或"yx"
分别调用mCustomScrollbar函数
$(".content").mCustomScrollbar({axis:"x" // 水平滚动条});$(".content").mCustomScrollbar({axis:"yx" // 垂直水平滚动条都有});
设置主题 具体主题http://manos.malihu.gr/repository/custom-scrollbar/demo/examples/scrollbar_themes_demo.html
$(".content").mCustomScrollbar({theme:"dark"});
您可以使用mCustomScrollbarfunctionUsage上的以下选项参数配置滚动条
$(selector).mCustomScrollbar({ option: value });