admin管理员组文章数量:1201790
I am using JS Select2 library to use as multiple options select. The select is positioned within a div
which is scrolled by its parent div
with css
- overflow-y: scroll
. The nested div
scrolls fine until an option is opened. When options are opened then the div
becomes un-scrollable unless it is scrolled on the select options. Not sure if the source of the problem is my html/css or its the select2
lib.
Thanks in advance for any help!
My markup:
<div id="topcontainer" style="padding-top: 100px; overflow-y: scroll; position: absolute; height: 1000px; width: 500px; background: #6d3353">
<div id="parent" style="position: relative; height: 3000px; width: 200px; background: #e4b9b9">
<select class="js-example-basic-multiple" name="states[]" multiple="multiple">
<option value="AL">aaaaaaa</option>
<option value="AL">bbbbbbb</option>
<option value="AL">ccccccc</option>
<option value="WY">ddddddd</option>
</select>
<script>
$(document).ready(function () {
$('.js-example-basic-multiple').select2();
});
</script>
</div>
I am using JS Select2 library to use as multiple options select. The select is positioned within a div
which is scrolled by its parent div
with css
- overflow-y: scroll
. The nested div
scrolls fine until an option is opened. When options are opened then the div
becomes un-scrollable unless it is scrolled on the select options. Not sure if the source of the problem is my html/css or its the select2
lib.
Thanks in advance for any help!
My markup:
<div id="topcontainer" style="padding-top: 100px; overflow-y: scroll; position: absolute; height: 1000px; width: 500px; background: #6d3353">
<div id="parent" style="position: relative; height: 3000px; width: 200px; background: #e4b9b9">
<select class="js-example-basic-multiple" name="states[]" multiple="multiple">
<option value="AL">aaaaaaa</option>
<option value="AL">bbbbbbb</option>
<option value="AL">ccccccc</option>
<option value="WY">ddddddd</option>
</select>
<script>
$(document).ready(function () {
$('.js-example-basic-multiple').select2();
});
</script>
</div>
Share Improve this question asked Mar 31, 2019 at 10:31 KonarasKonaras 6138 silver badges16 bronze badges
1 Answer
Reset to default 26Select2 intercept the scroll as you can see in the select2 source code.
I think its not a problem but a feature, because when you have it opened you want to scroll it, not the parents.
Anyway, looking at select2 events I found that we can override it by using the "select2:open" event and removing the added "scroll.select2" namespace events.
Example:
$('#states').select2({
dropdownParent: $('#parent')
});
$('#states').on('select2:open', function (e) {
const evt = "scroll.select2";
$(e.target).parents().off(evt);
$(window).off(evt);
});
You may test it here: Jsbin
本文标签: javascriptJS select2 plugin not scrolling when options are openStack Overflow
版权声明:本文标题:javascript - JS select2 plugin not scrolling when options are open - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738640620a2104286.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论