我使用过perfect-scrollbar js插件。滚动条工作正常。但是,当我再次为另一个内容(同一页)添加此滚动条时,它不适用于第二个div
。如何使用此插件在同一页面中添加多个滚动条?
JS
jQuery(document).ready(function ($) {
"use strict";
$('#Default').perfectScrollbar();
});
CSS
#Default.contentHolder { position:relative; margin:0px auto; margin-top: 20px; padding:0px; width: 285px; height: 450px; overflow: hidden; border: 1px solid #CCC; }
HTML
<div id="Default" class="contentHolder">
/*content goes here. scrollbar works fine here */
</div>
<div id="Default" class="contentHolder">
/*another content goes here. scrollbar does not work here*/
</div>
答案 0 :(得分:2)
使用Classes分配插件。 例如:
$('.contentHolder').perfectScrollbar();
或者如果它不起作用,您也可以使用.each
循环。例如:
$('.contentHolder').each(function(){
$(this).perfectScrollbar();
});
答案 1 :(得分:1)
对于最新版本,请使用此
$('.dialogInner').each(function(){ const ps = new PerfectScrollbar($(this)[0]); });
https://github.com/utatti/perfect-scrollbar/issues/246#issuecomment-356918832