Javascript 选择2和jScrollPane

Javascript 选择2和jScrollPane,javascript,jquery,jscrollpane,jquery-select2,jquery-jscrollpane,Javascript,Jquery,Jscrollpane,Jquery Select2,Jquery Jscrollpane,如何将Select2与jScrollPane结合使用 我想到了这个: $("select").select2({ width: "300px" }); $(document).on("select2-open", "select", function () { $('.select2-results').jScrollPane({ 'mouseWheelSpeed': 40 }); }); $(document).on("select2-close",

如何将Select2与jScrollPane结合使用

我想到了这个:

$("select").select2({
    width: "300px"
});

$(document).on("select2-open", "select", function () {
    $('.select2-results').jScrollPane({
        'mouseWheelSpeed': 40
    });
});

$(document).on("select2-close", "select", function () {
    $('.select2-results').data('jsp').destroy();
});

但使用(关闭)一次后,选择2停止工作(无法选择选项)。 有没有办法解决这个问题?我真的需要jScrollPane插件,而不是其他东西

更新1:

我通过在下拉菜单关闭时重新初始化select2,成功地实现了这一点,但我希望有更好的方法来实现这一点

$(document).on("select2-close", "select", function () {
    $('.select2-results').data('jsp').destroy();
    $("select").select2();
});
您需要更新

 $('.select2-results').jScrollPane({
            'mouseWheelSpeed': 40
        });

您将jScrollPane应用于错误的元素


这是一个有效的演示:

您将jscrollpane应用于错误的元素。请看我的回答,你编辑了错误的小提琴,在你的演示中没有jscrollpane滚动条处于活动状态,但无论如何,我正在应用正确的元素,它可以工作,但需要更正。啊,对不起,我已经更新了答案和演示。你能检查一下吗?你没看见吗?你得到了默认的滚动条,而不是jscrollpane一,检查我更新的演示,它应该如何工作,但我正在寻找更好的解决方案。
 $(this).parent(".select2-drop").jScrollPane({
            'mouseWheelSpeed': 40
        });