简体   繁体   English

Select2 +自定义滚动条

[英]Select2 + custom scrollbar

I'm trying to connect some custom scrollbars with Select2 4.0. 我正在尝试将某些自定义滚动条与Select2 4.0连接。 I found some old topics here on stackoverflow, but the solutions (with select2 3.4 ie) seems to be outdated. 我在这里发现了一些关于stackoverflow的老话题,但是解决方案(使用select2 3.4)似乎已经过时了。

I tried: jquery.scrollpane and jquery.nicescroll. 我尝试了:jquery.scrollpane和jquery.nicescroll。 Both scrollbars don't work with Select2 4.0. 两个滚动条均不适用于Select2 4.0。 Or maybe I did something wrong? 还是我做错了什么?

scrollpane solution (when used, "No results found" error occures) 滚动面板解决方案(使用时,出现“未找到结果”错误)

 $(function() { $('.select2-with-scroll').jScrollPane(); $w.on('resize', function() { $('.select2-with-scroll').jScrollPane(); }); }); 
 <select class="select2-with-scroll"> <option value=""></option> <option value="50">50</option> <option value="55">55</option> <option value="60">60</option> <option value="65">65</option> <option value="70">70</option> <option value="75">75</option> <option value="80">80</option> <option value="85">85</option> <option value="90">90</option> <option value="95">95</option> <option value="100">100</option> </select> 

nicescroll solution (absolutely no effects, HTML as above) nicescroll解决方案(完全没有效果,如上所示的HTML)

 $(document).ready( function() { $("select2-with-scroll").niceScroll(); } ); 

Is there any other custom scrollbars which I can use with Select2 4.0? 还有其他可与Select2 4.0一起使用的自定义滚动条吗? Or maybe it's possible to connect nicescroll or scrollpane with Select2? 或者也许可以将Nicescroll或scrollpane与Select2连接起来? Any help will be appreciated. 任何帮助将不胜感激。

With select2 v4.0 + nicescroll v3.6.6 try to make something like this 使用select2 v4.0 + nicescroll v3.6.6尝试做这样的事情

$('select').select2()
.on("select2:open", function () {
    $('.select2-results__options').niceScroll();
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM