- Overview
- Documents
Custom scrollbar plugin that’s fully customizable with CSS. Features vertical/horizontal scrolling, mouse-wheel support (via jQuery mousewheel plugin), scrolling buttons, scroll inertia with easing, auto-adjustable scrollbar length, nested scrollbars, scroll-to functionality, user defined callbacks and much more.
How to use it
Download the archive which contains all plugin files and examples. Extract and upload jquery.mCustomScrollbar.concat.min.js,jquery.mCustomScrollbar.css and mCSB_buttons.png to your web server.
Include jquery.mCustomScrollbar.css inside the head tag your html document
<link href="jquery.mCustomScrollbar.css" rel="stylesheet" type="text/css" />
Include jQuery library (if your project doesn’t use it already) and jquery.mCustomScrollbar.concat.min.js at the very bottom of your document, just before the closing body tag
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> <script src="jquery.mCustomScrollbar.concat.min.js"></script>
After files inclusion, call mCustomScrollbar function on the element you want to add custom scrollbars. The example below adds scrollbars to elements with class name content
<script> (function($){ $(window).load(function(){ $(".content").mCustomScrollbar(); }); })(jQuery); </script>
Your .content element(s) (or any other element you’re attaching the custom scrollbar) should have a typical styling of an overflowed block, e.g. a height (or max-height) value, overflow: auto (or hidden) and its content should be long enough to require a scrollbar.
To add a horizontal scrollbar, style your element accordingly (give it a width value and a wide enough content) and set the horizontalScroll option parameter of mCustomScrollbar to true
$(".content").mCustomScrollbar({ horizontalScroll:true });
jquery.mCustomScrollbar.css contains few ready-to-use scrollbar themes that you can apply easily on your scrollbars by setting the theme option parameter to the theme name you want
$(".content").mCustomScrollbar({ theme:"light" });
Configuration
mCustomScrollbar function can get the following option parameters in order to customize scrollbar behavior and functionality
set_width: false |
Set the width of your content (overwrites CSS width), value in pixels (integer) or percentage (string). |
set_height: false |
Set the height of your content (overwrites CSS height), value in pixels (integer) or percentage (string). |
horizontalScroll: Boolean |
Add horizontal scrollbar (default is vertical), values: true, false. |
scrollInertia: Integer |
Scrolling inertia (easing), value in milliseconds (0 for no scrolling inertia). |
mouseWheel: Boolean |
Mouse-wheel support, values: true, false. |
mouseWheelPixels: "auto" |
Mouse-wheel scrolling pixels amount, value in pixels (integer) or “auto” (script calculates and sets pixels amount according to content length). |
autoDraggerLength: Boolean |
Auto-adjust scrollbar height/width according to content, values: true, false. |
autoHideScrollbar: Boolean |
Automatically hide the scrollbar when idle or mouse is not over the content. |
scrollButtons:{ enable: Boolean } |
Scroll buttons support, values: true, false. |
scrollButtons:{ scrollType: String } |
Scroll buttons scroll type, values: "continuous" (scroll continuously while pressing the button), "pixels" (scroll by a fixed number of pixels on each click) See both scroll types in action. |
scrollButtons:{ scrollSpeed: "auto" } |
Scroll buttons continuous scrolling speed, integer value or “auto” (script calculates and sets the speed according to content length). |
scrollButtons:{ scrollAmount: Integer } |
Scroll buttons pixels scrolling amount, value in pixels. |
advanced:{ updateOnBrowserResize: Boolean } |
Update scrollbars on browser resize (for fluid content blocks & layouts based on percentages), values: true, false. Set to false only when your content has fixed dimensions. |
advanced:{ updateOnContentResize: Boolean } |
Auto-update scrollbars on content resize (useful when adding/changing content programmatically), values: true, false Setting this to true makes the script check for content length changes (every few milliseconds) and automatically call plugin’s update method to adjust the scrollbar accordingly. |
advanced:{ autoExpandHorizontalScroll: Boolean } |
Auto-expanding content’s width on horizontal scrollbars, values: true, false Set to true if you have horizontal scrollbar on content that will change on-the-fly. Demo contains blocks with images and horizontal scrollbars that use this option parameter. |
advanced:{ autoScrollOnFocus: Boolean } |
Auto-scrolling on elements that have focus (e.g. scrollbar automatically scrolls-to form textfields when the TAB key is pressed), values: true, false. |
advanced:{ normalizeMouseWheelDelta: Boolean } |
Normalize mouse-wheel delta (-1/1), values: true, false. |
contentTouchScroll: Boolean |
Additional scrolling method by touch-swipe content (for touch enabled devices), values: true, false. |
callbacks:{ onScrollStart: function(){} } |
User defined callback function, triggered on scroll start event. You can call your own function(s) each time a scroll event begins (callbacks demo). Example: callbacks:{ onScrollStart:function(){ console.log("scrolling started..."); } } |
callbacks:{ onScroll: function(){} } |
User defined callback function, triggered on scroll event. Call your own function(s) each time a scroll event completes (callbacks demo). Example: callbacks:{ onScroll:function(){ console.log("content scrolled..."); } } |
callbacks:{ onTotalScroll: function(){} } |
User defined callback function, triggered when scroll end-limit is reached (callbacks demo). Example: callbacks:{ onTotalScroll:function(){ console.log("scrolled to end of content."); } } |
callbacks:{ onTotalScrollBack: function(){} } |
User defined callback function, triggered when scroll beginning is reached (callbacks demo). Example: callbacks:{ onTotalScrollBack:function(){ console.log("scrolled back to the beginning of content."); } } |
callbacks:{ onTotalScrollOffset: Integer } |
Scroll end-limit offset, value in pixels (see example). |
callbacks:{ onTotalScrollBackOffset: Integer } |
Scroll beginning offset, value in pixels. |
callbacks:{ whileScrolling: function(){} } |
User defined callback function, triggered while scrolling (callbacks demo). Example: callbacks:{ whileScrolling:function(){ console.log("scrolling..."); } } |
More infomation at: http://manos.malihu.gr/jquery-custom-content-scroller/