Its a simple, fast, lightweight (~2kB) plugin for jQuery 1.7+
that allows to control bar view using css.

+ Supporting touch, wheel, middle button and any kind of scrolling
+ As fast as native
+ Weight incredible small
+ Tested with IE7+, mobile and modern browsers

Example

Add content Remove content Horizontal test Init Destroy

Usage

To init custom-scroll, include files on your page, and init on desired elements

  1. <!-- Custom-scroll CSS -->
  2. <link rel="stylesheet" href="css/jquery.custom-scroll.css">
  3. <!-- jQuery 1.7.0+ -->
  4. <script src="js/jquery.js"></script>
  5. <!-- Custom-scroll JS -->
  6. <script src="js/jquery.custom-scroll.js"></script>
  1. //Custom-scroll init example
  2. $('#example').customScroll();

Options

There is some options you may need:

  1. // Full list of options with default values
  2. // All options are optional
  3. $('#example').customScroll({
  4. prefix: 'custom-scroll_',
  5. /* vertical */
  6. barMinHeight: 10,
  7. offsetTop: 0,
  8. offsetBottom: 0,
  9. /* will be added to offsetBottom in case of horizontal scroll */
  10. trackWidth: 10,
  11. /* horizontal */
  12. barMinWidth: 10,
  13. offsetLeft: 0,
  14. offsetRight: 0,
  15. /* will be added to offsetRight in case of vertical scroll */
  16. trackHeight: 10,
  17. /* each bar will have custom-scroll_bar-x or y class */
  18. barHtml: '<div />',
  19. /* both vertical or horizontal bar can be disabled */
  20. vertical: true,
  21. horizontal: true
  22. });
  23. // To recalculate bar position use same method without options
  24. $('#example').customScroll();
  25. // If you need to remove custom-scroll there is 'destroy' method
  26. $('#example').customScroll('destroy');
  27. // To change/get default options use
  28. $.fn.customScroll(someOptions);

How it works

After you init custom-scroll, it adds class to container, and makes new inner and bar
If there is already elements with those classes, they will be used

  1. <!-- before -->
  2. <div>
  3. ...
  4. </div>
  5. <!-- after: adds class -->
  6. <div class="custom-scroll_container">
  7. <!-- adds inner -->
  8. <div class="custom-scroll_inner">
  9. ...
  10. </div>
  11. <!-- adds barHtml from options with class -->
  12. <div class="custom-scroll_bar"></div>
  13. <div class="custom-scroll_bar-x"></div>
  14. </div>

Init custom-scroll to see demo

Sed do eiusmod tempor incididunt. Duis aute irure dolor in reprehenderit, sed ut perspiciatis.

Ut aliquip ex ea commodo consequat. Sed ut perspiciatis. Explicabo, et quasi architecto beatae vitae dicta sunt.

Ut aliquip ex ea commodo consequat, neque porro quisquam est, accusantium doloremque laudantium, nemo enim ipsam voluptatem.

Sunt in culpa qui officia. Sed do eiusmod tempor incididunt, nemo enim ipsam voluptatem.

In voluptate velit esse cillum dolore, consectetur adipisicing elit, unde omnis iste natus error sit voluptatem.

Sunt in culpa qui officia, nemo enim ipsam voluptatem, aspernatur aut odit aut fugit, duis aute irure dolor in reprehenderit, sed ut perspiciatis.

Quia voluptas sit. Quia voluptas sit, excepteur sint occaecat cupidatat non proident, ut labore et dolore magna aliqua, explicabo.

sed do eiusmod tempor incididunt, unde omnis iste natus error sit voluptatem, in voluptate velit esse cillum dolore

In voluptate velit esse cillum dolore, consectetur adipisicing elit, unde omnis iste natus error sit voluptatem.

Sed do eiusmod tempor incididunt. Duis aute irure dolor in reprehenderit, sed ut perspiciatis.

Init Destroy

Themes

Customize scroll any way you want using CSS

Pretty

Track added by html+css
view css


Invisible

Bar appear only on hover
view css


Native

Just to compare



Add content Remove content Horizontal test

Textarea

Usable with textarea either

Add content Remove content

Hidden, max-height elements, paddings

1. Hidden element should be inited right after it will be shown. Since its not possible to properly count all dimensions of hidden elements

2. Max-height works fine, if you dont use horizontal scroll

3. Avoid using padding-top and padding-bottom for scrolling container. May have glitches.

Toggle Add content Remove content Init Destroy

Advanced usage

Custom-scroll is listening the scroll event at inner element, so you can use jQuery scrollTop method to control position.

That will help if you want more advanced scroll like in example below


Advanced
Track is clickable
view css
view js

Add content Remove content