3 ms·
My two cents. You'll never be able to match the scroll smoothly listening for scroll events. Use requestAnimationFrame and listen for changes in window.scrollTo
by yuchi 13y ago
My two cents. You'll never be able to match the scroll smoothly listening for scroll events. Use requestAnimationFrame and listen for changes in window.scrollTop.
- ars 13y agoListen for changes? Or poll for changes? Wouldn't your way consume a lot of unnecessary CPU?
- yuchi 13y agoNot exactly poll. Use scroll events to start your polling; after the second time your loop function doesn't find a change in the scrollTop, stop requesting frames. Even without this guard, with just the `old !== getScrollTop()` it doesn't eat so much CPU neither.