scroll2Top function that uses requestAnimationFrame and easing for animation
# Get the latest snapshot
$ git clone git@github.com:pinceladasdaweb/scroll2Top.git
View demo here
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.
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 |
![]() |
![]() |
![]() |
![]() |
![]() |
---|---|---|---|---|
IE 10+ ✔ | Latest ✔ | Latest ✔ | Latest ✔ | Latest ✔ |
Do you need support for older browsers? Add a requestAnimationFrame polyfill.
Check CONTRIBUTING.md for more information.
Check Releases for detailed changelog.