Last active
January 6, 2018 01:19
-
-
Save abiodun0/2f72c32ab01f3c2b3a3e5e472971e677 to your computer and use it in GitHub Desktop.
requestAnimation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getPinStyle (pin, scrollPosition) { | |
// do some calculation based on the pin that was passed in and the current scroll position | |
return { rotate, scale, translate } | |
} | |
requestAnimationFrame(function frame () { | |
pins.forEach(pin => applyPinStyles(pin, getPinStyle(pin, window.scrollTop))) | |
requestAnimationFrame(frame) | |
}) | |
// `requestAnimationFrame` in this context saves you from a certain kind of bug in `setInterval`, | |
// which is that `setInterval` calls are scheduled based on the computer clock (loosely speaking) | |
// while `rAF` schedules the next call subsequent to the previous call. | |
//But `setInterval` can occasionally drop frames (IIRC), or stack frames within the same event loop turn. | |
// It’s a bit of a consistency nightmare. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment