phdphd Posted April 21, 2018 Share Posted April 21, 2018 Hi All, I made some jQuery that successfully scrolls the viewport to the top border of a scrollable div when the user scrolls the contents of that div. The issue is that after that I cannot scroll the whole page (the div itself remains scrollable). Here is what my jQuery looks like : $("#scrollable_div").on( 'scroll', function(){ //here goes some code to calculate the distance to move $('html, body').animate({scrollTop: distance},'slow'); }); Thanks for your help! Quote Link to comment https://forums.phpfreaks.com/topic/307187-page-gets-frozen-after-jquery-on-scroll-event-applied-to-a-div/ Share on other sites More sharing options...
phdphd Posted April 21, 2018 Author Share Posted April 21, 2018 I've just posted a jsfiddle about this issue https://jsfiddle.net/949bm7vq/ Quote Link to comment https://forums.phpfreaks.com/topic/307187-page-gets-frozen-after-jquery-on-scroll-event-applied-to-a-div/#findComment-1558000 Share on other sites More sharing options...
phdphd Posted April 21, 2018 Author Share Posted April 21, 2018 Well, I think I found a solution with clearQueue(). Any comments welcome! https://jsfiddle.net/6sempeav/ Quote Link to comment https://forums.phpfreaks.com/topic/307187-page-gets-frozen-after-jquery-on-scroll-event-applied-to-a-div/#findComment-1558002 Share on other sites More sharing options...
maxxd Posted April 21, 2018 Share Posted April 21, 2018 I believe that using animate() to scroll the page down still fires the scroll() event in the browser. If I'm correct about that, you're basically calling the function in an almost infinite loop until the page scrolls to the value of distance - which would freeze your page. Quote Link to comment https://forums.phpfreaks.com/topic/307187-page-gets-frozen-after-jquery-on-scroll-event-applied-to-a-div/#findComment-1558003 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.