Created
December 22, 2017 20:19
-
-
Save ryangittings/c1235a7bb0a8cb248592fdca3eef794e to your computer and use it in GitHub Desktop.
Auto Scroll
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
var scrollElement = function (element, scrollPosition, duration) { | |
var style = element.style; | |
// setup CSS transition duration and easing function | |
style.webkitTransition = | |
style.transition = duration + 's'; | |
style.webkitTransitionTimingFunction = | |
style.TransitionTimingFunction = 'ease-in-out'; | |
// use translate3d to force hardware acceleration | |
style.webkitTransform = | |
style.Transform = 'translate3d(0, ' + -scrollPosition + 'px, 0)'; | |
setTimeout(function() { | |
style.webkitTransform = | |
style.Transform = 'translate3d(0, 0, 0)'; | |
}, duration * 1000) | |
} | |
window.onload = function(e){ | |
setTimeout(function() { | |
var scrollBody = scrollElement(document.querySelector('body'), 1000, 8); | |
}, 1000); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment