admin管理员组

文章数量:1315792

I'm using slimScroll jQuery plugin and it seems that the destroy option doesn't pletely destroy the plugin effect on the site.

For example, if you try to destroy the plugin and then scroll over the previously scrollable content, the site scrolling functionality stops working. You will be able to scroll using the scrollbar, not not by using the mouse wheel / trackpad.

Here's a reproduction of the bug

Notice a couple of things:

  • Scrolling with mouse wheel / trackpad over the previously scrollable element blocks the scrolling.
  • Scrolling outside the previously scrollable element works as expected.
  • If you scroll the slimScroll until its bottom before destroying it, when destroying it, it works properly as it should in any occasion.

I've already reported it in the repository, but no answers are given. It seems its kind of abandoned. I tried different proposed solutions, but none of them work properly.

The lack of a proper method to destroy the plugin seems to be the problem...

Used code in jsfiddle:

$('.scrollable').slimScroll({
    allowPageScroll: true,
    height: '250px',
    size: '10px',
    alwaysVisible: true
});

$('.destroy').click(function(){
    $('.scrollable').slimScroll({
        destroy:true
    });
});

I'm using slimScroll jQuery plugin and it seems that the destroy option doesn't pletely destroy the plugin effect on the site.

For example, if you try to destroy the plugin and then scroll over the previously scrollable content, the site scrolling functionality stops working. You will be able to scroll using the scrollbar, not not by using the mouse wheel / trackpad.

Here's a reproduction of the bug

Notice a couple of things:

  • Scrolling with mouse wheel / trackpad over the previously scrollable element blocks the scrolling.
  • Scrolling outside the previously scrollable element works as expected.
  • If you scroll the slimScroll until its bottom before destroying it, when destroying it, it works properly as it should in any occasion.

I've already reported it in the repository, but no answers are given. It seems its kind of abandoned. I tried different proposed solutions, but none of them work properly.

The lack of a proper method to destroy the plugin seems to be the problem...

Used code in jsfiddle:

$('.scrollable').slimScroll({
    allowPageScroll: true,
    height: '250px',
    size: '10px',
    alwaysVisible: true
});

$('.destroy').click(function(){
    $('.scrollable').slimScroll({
        destroy:true
    });
});
Share Improve this question edited Apr 3, 2021 at 11:03 Syscall 19.8k10 gold badges43 silver badges58 bronze badges asked Nov 6, 2014 at 15:25 AlvaroAlvaro 41.6k31 gold badges172 silver badges347 bronze badges 1
  • What I did in a current project, although it's not the most efficient way, is clone the element I wish to make scrollable before I make it scrollable. And when I want to get rid of it, I just replace it. – MisterBla Commented Nov 6, 2014 at 15:37
Add a ment  | 

1 Answer 1

Reset to default 8 +50

The problem is that the plugin is not removing the registered events. This should fix the problem:

$('.destroy').click(function(){
    $('.scrollable').slimScroll({
        destroy:true
    });

    var $elem = $('.scrollable'),
    events = jQuery._data( $elem[0], "events" );

    if (events) {
        jQuery._removeData( $elem[0], "events" );
    }

});

本文标签: javascriptslimScroll destroy doesn39t unbind the scroll eventsStack Overflow