Create Scrollable Container With Custom Scrollbar - scrollPanel
File Size: | 68.9 KB |
---|---|
Views Total: | 4600 |
Last Update: | |
Publish Date: | |
Official Website: | Go to website |
License: | MIT |

scrollPanel is a jQuery plugin (~2kb minified) that transforms a DIV container into a scrollable panel where you can customize the scrollbar using your own CSS rules.
How to use it:
1. Download and import the jquery-scrollpanel.js
script after jQuery.
<script src="https://code.jquery.com/jquery-3.3.1.min.js" integrity="sha384-tsQFqpEReu7ZLhBV2VZlAu7zcOV+rXbYlF2cqB8txI/8aZajjp4Bqd+V6D5IgvKT" crossorigin="anonymous"> </script> <script src="dist/jquery-scrollpanel.js"></script>
2. To enable the mousewheel on the scrllable panel, import the latest jQuery mouse wheel plugin in the document.
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-mousewheel/3.1.13/jquery.mousewheel.min.js"></script>
3. Attach the function to the target container.
<div class="scrollpanel"> Any content here </div>
$(".scrollpanel").scrollpanel();
4. This will transform the DIV container into a scrollable panel:
<div class="scrollpanel"> <div class="sp-viewport"> <div class="sp-container"> Any content here </div> </div> <div class="sp-scrollbar"> <div class="sp-thumb"></div> </div> </div>
5. Customize the scrollbar in the CSS:
.scrollpanel .sp-scrollbar { width: 10px; background-color: #ccc; cursor: pointer; } .scrollpanel .sp-scrollbar .sp-thumb { background-color: #aaa; transition: height 0.2s ease-in-out; } .scrollpanel .sp-scrollbar.active .sp-thumb { background-color: #999; }
6. Customize the CSS prefix.
$(".scrollpanel").scrollpanel({ prefix: 'sp-' });
Changelog:
2020-07-28
- JS updated
2019-04-15
- v1.1.0: update
This awesome jQuery plugin is developed by lrsjng. For more Advanced Usages, please check the demo page or visit the official website.