Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resize can continue to work, even after slider is destroyed. #293

Open
dobromir-hristov opened this issue Aug 14, 2019 · 2 comments
Open

Comments

@dobromir-hristov
Copy link

I am using the slider in an SPA and I got allot of errors from mobile Chrome. Turns out the resize listener can get triggered, just before I destroy the slider when navigating away from a page. That causes the slider to error out as there is a 200ms debounce on that event, which gets called after the slider is not in the DOM.

@davidghi do you think it is OK to add a check on those throttled callbacks, to see if the instance is not destroyed, elements are in the DOM and what knot?

@davidghi
Copy link
Member

davidghi commented Sep 4, 2019

Hi. Sorry for the late reply! I will try to implement a fix for this issue in the next update. For now, a fix could be to create a custom destroy function which clears the 'resize' timer first and then call's the slider's 'destroy' method. For example:

function customDestroy() {
    var $slider = jQuery( '.slider-pro' ),
          sliderId = $slider.data( 'sliderPro' ).uniqueId;

    $( window ).off( 'resize.' + sliderId );
    
    setTimeout( function() {
        $slider.sliderPro( 'destroy' );
    }, 200 );
}

Best,
David

@dobromir-hristov
Copy link
Author

Hah I did not think of that... Will give it a try.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants