Last active
September 11, 2018 14:43
-
-
Save snowleo208/6bd036b046f810e7fe52ebb8e52c7ed6 to your computer and use it in GitHub Desktop.
This file contains 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
// if target is 0 (back to top), | |
// the position is: | |
// current pos + (current pos * percentage of duration) | |
// if target > 0 (not back to top), | |
// the positon is current pos + (target pos * percentage of duration) | |
pos = (target === 0)? (firstPos - (firstPos * progress)) : (firstPos + (target * progress)); | |
window.scrollTo(0, pos); | |
if(target !== 0 && pos >= (firstPos + target) || target === 0 && pos <= 0) { | |
cancelAnimationFrame(start); | |
if(element) { element.focus(); } | |
pos = 0; | |
} else { | |
window.requestAnimationFrame(showAnimation); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment