With NPM run the following command:
npm install @axn/jquery-backtotop --save
Load the script:
<script src="jquery.js"></script>
<script src="jquery.backtotop.js"></script>
Put a button:
<button id="btn-back-to-top">Back to top</button>
Position it:
#btn-back-to-top {
position: fixed;
bottom: 15px;
right: 15px;
display: none;
}
Run the script:
(function($) {
$('#btn-back-to-top').backtotop();
})(jQuery);
With options:
(function($) {
$('#btn-back-to-top').backtotop({
showAt: 200,
fadeInDelay: 400,
fadeOutDelay: 400,
scrollTopDelay: 600
});
})(jQuery);