Created
March 16, 2013 19:52
-
-
Save onestepcreative/5178019 to your computer and use it in GitHub Desktop.
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 scrollTop(step) { | |
| var start = window.pageYOffset; | |
| var count = 0; | |
| var intervalRef = setInterval( (function(interval, curOffset) { | |
| return function() { | |
| curOffset -= (interval * step); | |
| console.info("offset = " + curOffset); | |
| window.scrollTo(0, curOffset); | |
| console.info("pageYoffset = " + window.pageYOffset); | |
| count++; | |
| if(count > 150 || curOffset < 0) clearInterval(intervalRef); | |
| } | |
| })(step, start--), 50); | |
| } | |
| // scroll to the top from the middle of the page in about 5 seconds. | |
| scrollTop(5); | |
| // scroll to the top in about 1 second | |
| scrollTop(15); | |
| // scrolls to the top very fast! | |
| scrollTop(35); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment