Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

slimScroll destroy doesn't unbind the scroll events

I'm using slimScroll jQuery plugin and it seems that the destroy option doesn't completely 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
    });
});
like image 795
Alvaro Avatar asked Jan 01 '26 14:01

Alvaro


1 Answers

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" );
    }

});
like image 173
Zhivko Donev Avatar answered Jan 03 '26 04:01

Zhivko Donev



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!