This is a simple function for animating scroll.
- No dependency on extra libraries.
- If user scrolls while animation is running, scroll animation would be immediately canceled.
- Use as a single script or through bower.
- If you want full browser support include this library: https://github.com/mathiasbynens/document.scrollingElement
button.addEventListener('click', function () {
animatedScrollTo(
document.body, // element to scroll with (most of times you want to scroll with whole <body>)
0, // target scrollY (0 means top of the page)
10000, // duration in ms
function() { // callback function that runs after the animation (optional)
console.log('done!')
}
);
});
This will scroll to top of the page and the animation will run for 10 seconds (10000ms).
bower install animated-scrollto
Just import with <script>
and global function animatedScrollTo
will be available for you.
npm install animated-scrollto
In your browserify powered js:
var animatedScrollTo = require('animated-scrollto')
MIT