Can someone explaine and help me with this. My webpage is slugish because the scroll function is dragging it down. I need to add a delay but don’t understand how to do this.
$(window).scroll(handleScroll);
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You could write a simple
throttledebounce function to limit the times per second the scroll event will be handled.This will make sure there’s at least 100ms between each call to
handleScroll(or, in other words, it’s called at most 10 times per second).As zzzzBov pointed out, what Zakas describes as a throttle function is actually a debounce function. The difference is that debounce discards the superfluous scroll events, while a throttle function should queue them up to be handled later (but at a given maximum rate).
In the case of scroll events, you don’t want real throttling.