To use smooth-scrollbar, initialize it on a container element using Scrollbar.init().
Important: The container element must have a defined width or height and be natively scrollable (e.g., overflow: auto) before initialization. This ensures the content inside is larger than the container itself.
Using ES6 Modules (Recommended)
Use this method with bundlers like Webpack or Rollup:
import Scrollbar from 'smooth-scrollbar';
Scrollbar.init(document.querySelector('#my-scrollbar'), options);
Using UMD Bundle
If you are not using a bundler, load the script via a <script> tag:
<script src="dist/smooth-scrollbar.js"></script>
<script>
var Scrollbar = window.Scrollbar;
Scrollbar.init(document.querySelector('#my-scrollbar'), options);
</script>