A simple vanilla js back-to-top button.
npm install renancalmet/backtotop
In document head :
<link rel="stylesheet" href="node_modules/backtotop/backtotop.css">
At the end of <body>
:
<script src="node_modules/backtotop/index.js"></script>
<script>
const bouton = new backToTop(700, '.button');
</script>
The class parameters are :
-
700
: the first pixel from which the backtotop button is displayed. -
'.button'
: the CSS selector to identify the button.
- Add positioning parameters
- Stylize appearance/disappearance
- Make it a real node module by
default export
ing the class + making adist/backtotop.js
following this tutorial