Jump to content

Page Gets Frozen After jQuery On Scroll Event Applied To a DIV


phdphd

Recommended Posts

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!

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.