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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.