Skip to content

Instantly share code, notes, and snippets.

@ryangittings
Created December 22, 2017 20:19
Show Gist options
  • Save ryangittings/c1235a7bb0a8cb248592fdca3eef794e to your computer and use it in GitHub Desktop.
Save ryangittings/c1235a7bb0a8cb248592fdca3eef794e to your computer and use it in GitHub Desktop.
Auto Scroll
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