Search code examples
jqueryselectscrollbarjquery-select2mcustomscrollbar

Malihu jQuery Custom Scrollbar with Select 2


Scrollbar shows only on first opening and no more. What I did wrong?

$('.select').on('select2:open', function () {
    function showScroll() {
        $('.select2-results__options').mCustomScrollbar();
    }
    setTimeout(showScroll, 1);
});

Solution

  • I found a solution:

    $('.select').on('select2:open', function () {
        $('.select__dropdown .select2-results__options').mCustomScrollbar('destroy');
        $('.select__dropdown .select2-results__options').mCustomScrollbar('update');
        setTimeout(function() {
            $('.select__dropdown .select2-results__options').mCustomScrollbar({
                axis: 'y',
                scrollbarPosition: 'inside',
                advanced:{
                    updateOnContentResize: true
                },
                live: true
            });
        }, 0);
    });