Awesome
scroll2Top
scroll2Top function that uses requestAnimationFrame and easing for animation
Getting Started
# Get the latest snapshot
$ git clone git@github.com:pinceladasdaweb/scroll2Top.git
Demo
View demo here
How to use?
scroll2Top is a Vanilla JS plugin with no dependencies. Include the scroll2Top.min.js
before your </body>
tag:
<script src="path/to/scroll2Top.min.js"></script>
And use it:
<script>
var btn = document.querySelector('#btn'),
target = document.querySelector('p').offsetTop;
btn.addEventListener('click', function(e){
e.preventDefault();
scroll2Top(target, function () {
alert('Hello!!!')
}, 1400);
});
</script>
scroll2Top supports AMD, CommomJS and Browser.
Options
The script expect the following options:
Value | Description |
---|---|
to | Integer. Required. How far to offset the scrolling anchor location in pixels |
callback | Optional. Function to run after scrolling |
duration | Integer. Optional. How fast to complete the scroll in milliseconds |
Browser Support
IE 10+ ✔ | Latest ✔ | Latest ✔ | Latest ✔ | Latest ✔ |
Do you need support for older browsers? Add a requestAnimationFrame polyfill.
Contributing
Check CONTRIBUTING.md for more information.
History
Check Releases for detailed changelog.