This website uses cookies to personalise ads and to analyse traffic ok
web design

jQuery custom content scroller

jQuery custom content scroller

Highly customizable custom scrollbar jQuery plugin. Features include vertical and/or horizontal scrollbar(s), adjustable scrolling momentum, mouse-wheel (via jQuery mousewheel plugin), keyboard and touch support, ready-to-use themes and customization via CSS, RTL direction support, option parameters for full control of scrollbar functionality, methods for triggering actions like scroll-to, update, destroy etc., user-defined callbacks and more.

Current version 3.1.5 (Changelog)
Upgrading from version 2

When upgrading from version 2.x to 3.x it’s important to use version 3 CSS and .png files. Version 3 is backwards compatible but it’s also a huge overhaul. One significant change is that you don’t need to call the update method manually (the script does it automatically). For more info see changelog.

Version 2 is still maintained and updated here.


How to use it

Get started by downloading the archive which contains the plugin files (and a large amount of HTML demos and examples). Extract and upload jquery.mCustomScrollbar.concat.min.js, jquery.mCustomScrollbar.css and mCSB_buttons.png to your web server (alternatively you can load plugin files from a CDN).

Instead of hosting the plugin files on your web server, you can load them directly from a CDN like jsdelivr, Github etc.

  • jsdelivr versioned/minified
    • //cdn.jsdelivr.net/jquery.mcustomscrollbar/3.0.6/jquery.mCustomScrollbar.concat.min.js
    • //cdn.jsdelivr.net/jquery.mcustomscrollbar/3.0.6/jquery.mCustomScrollbar.min.css
    • //cdn.jsdelivr.net/jquery.mcustomscrollbar/3.0.6/mCSB_buttons.png
  • Github latest/minified
    • //malihu.github.io/custom-scrollbar/jquery.mCustomScrollbar.concat.min.js
    • //malihu.github.io/custom-scrollbar/jquery.mCustomScrollbar.min.css
    • //malihu.github.io/custom-scrollbar/mCSB_buttons.png


HTML

Include jquery.mCustomScrollbar.css in the head tag your HTML document (more info)

jquery.mCustomScrollbar.css contains the styling of the custom scrollbar and themes. It should normally be included in the head tag of your html (typically before any script tags). If you wish to reduce http requests and/or have all your website stylesheet in a single file, you should move/copy scrollbars styling in your main CSS document.

mCSB_buttons.png contains all the button arrows (up, down, left and right) as image sprites for all scrollbar themes. The plugin archive contains the PSD source (source-files/mCSB_buttons.psd) so you can change them or add your own. This file should be in the same directory with plugin stylesheet.


<link rel="stylesheet" href="/path/to/jquery.mCustomScrollbar.css" />

Include jQuery library (if your project doesn’t use it already) and jquery.mCustomScrollbar.concat.min.js in the head tag or at the very bottom of your document, just before the closing body tag

Some frameworks and CMS include jQuery library in the head tag to make sure it’s loaded when other scripts request it. Usually, including .js files on the bottom of the HTML document (just before the closing body tag) is recommended for better performance. In any case, jQuery must be included first, before plugin scripts.


<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="/path/to/jquery.mCustomScrollbar.concat.min.js"></script>

CSS

The element(s) you want to add scrollbar(s) should have the typical CSS properties of an overflowed block which are a height (or max-height) value, an overflow value of auto (or hidden) and content long enough to require scrolling. For horizontal scrollbar, the element should have a width (or max-width) value set.

If you prefer to set your element’s height/width via javascript, you can use the setHeight/setWidth option parameters.

Initialization

Initialize via javascript

After files inclusion, call mCustomScrollbar function on the element selector you want to add the scrollbar(s)

<script>
    (function($){
        $(window).on("load",function(){
            $(".content").mCustomScrollbar();
        });
    })(jQuery);
</script>

more info

The code is wrapped in (function($){ ... })(jQuery);. This ensures no conflict between jQuery and other libraries using $ shortcut (see Avoiding Conflicts with Other Libraries for more info). The plugin function is called in $(window).on("load") so it executes after all page elements (like images) are loaded.

You can change the function selector ".content" to any selector you want (an element id, class name, js variable etc.). For instance, if you want custom scrollbars to apply on the element with id content-1, you simply do:

$("#content-1").mCustomScrollbar();

You may also have multiple selectors by inserting comma separated values

$(".content,#content-1").mCustomScrollbar();

The above code adds custom scrollbars to a)every element with class name content and b)the element with id content-1.

Additionally, you may want to call mCustomScrollbar multiple times within a page in order to set different options (configuration and option parameters explained below) for each selector

<script>
  (function($){
    $(window).on("load",function(){
      $("#vertical-content").mCustomScrollbar({
        theme:"light-3",
        scrollButtons:{
          enable:true
        }
      });
      $("#horizontal-content").mCustomScrollbar({
        axis:"x",
        theme:"3d"
      });
    });
  })(jQuery);
</script>

Initialize via HTML

Add the class mCustomScrollbar to any element you want to add custom scrollbar(s) with default options. Optionally, set its axis via the HTML data attribute data-mcs-axis (e.g. "x" for horizontal and "y" for vertical) and its theme via data-mcs-theme. For example:

<div class="mCustomScrollbar" data-mcs-theme="dark">
  <!-- your content -->
</div>

Basic configuration & option parameters

axis

By default, the script applies a vertical scrollbar. To add a horizontal or 2-axis scrollbars, invoke mCustomScrollbar function with the axis option set to "x" or "yx" respectively

$(".content").mCustomScrollbar({
    axis:"x" // horizontal scrollbar
});
$(".content").mCustomScrollbar({
    axis:"yx" // vertical and horizontal scrollbar
});

theme

To quickly change the appearance of the scrollbar, set the theme option parameter to any of the ready-to-use themes available in jquery.mCustomScrollbar.css, for example:

$(".content").mCustomScrollbar({
    theme:"dark"
});

Configuration

You can configure your scrollbar(s) using the following option parameters on mCustomScrollbar function
Usage $(selector).mCustomScrollbar({ option: value });

setWidth: false
Set the width of your content (overwrites CSS width), value in pixels (integer) or percentage (string).
setHeight: false
Set the height of your content (overwrites CSS height), value in pixels (integer) or percentage (string).
setTop: 0
Set the initial css top property of content, accepts string values (css top position).
Example: setTop: "-100px".
setLeft: 0
Set the initial css left property of content, accepts string values (css left position).
Example: setLeft: "-100px".
axis: "string"
Define content’s scrolling axis (the type of scrollbars added to the element: vertical and/of horizontal).
Available values: "y", "x", "yx".

  • axis: "y" – vertical scrollbar (default)
  • axis: "x" – horizontal scrollbar
  • axis: "yx" – vertical and horizontal scrollbars
scrollbarPosition: "string"
Set the position of scrollbar in relation to content.
Available values: "inside", "outside".
Setting scrollbarPosition: "inside" (default) makes scrollbar appear inside the element. Setting scrollbarPosition: "outside" makes scrollbar appear outside the element. Note that setting the value to "outside" requires your element (or parent elements) to have CSS position: relative (otherwise the scrollbar will be positioned in relation to document’s root element).
scrollInertia: integer
Set the amount of scrolling momentum as animation duration in milliseconds.
Higher value equals greater scrolling momentum which translates to smoother/more progressive animation. Set to 0 to disable.
autoDraggerLength: boolean
Enable or disable auto-adjusting scrollbar dragger length in relation to scrolling amount (same bahavior with browser’s native scrollbar).
Set autoDraggerLength: false when you want your scrollbar to (always) have a fixed size.
autoHideScrollbar: boolean
Enable or disable auto-hiding the scrollbar when inactive.
Setting autoHideScrollbar: true will hide the scrollbar(s) when scrolling is idle and/or cursor is out of the scrolling area.
Please note that some special themes like “minimal” overwrite this option.
autoExpandScrollbar: boolean
Enable or disable auto-expanding the scrollbar when cursor is over or dragging the scrollbar.
alwaysShowScrollbar: integer
Always keep scrollbar(s) visible, even when there’s nothing to scroll.

  • alwaysShowScrollbar: 0 – disable (default)
  • alwaysShowScrollbar: 1 – keep dragger rail visible
  • alwaysShowScrollbar: 2 – keep all scrollbar components (dragger, rail, buttons etc.) visible
snapAmount: integer
Make scrolling snap to a multiple of a fixed number of pixels. Useful in cases like scrolling tabular data, image thumbnails or slides and you need to prevent scrolling from stopping half-way your elements. Note that your elements must be of equal width or height in order for this to work properly.
To set different values for vertical and horizontal scrolling, use an array: [y,x]
snapOffset: integer
Set an offset (in pixels) for the snapAmount option. Useful when for example you need to offset the snap amount of table rows by the table header.
mouseWheel:{ enable: boolean }
Enable or disable content scrolling via mouse-wheel.
mouseWheel:{ scrollAmount: integer }
Set the mouse-wheel scrolling amount (in pixels). The default value "auto" adjusts scrolling amount according to scrollable content length.
mouseWheel:{ axis: "string" }
Define the mouse-wheel scrolling axis when both vertical and horizontal scrollbars are present.
Set axis: "y" (default) for vertical or axis: "x" for horizontal scrolling.
mouseWheel:{ preventDefault: boolean }
Prevent the default behaviour which automatically scrolls the parent element when end or beginning of scrolling is reached (same bahavior with browser’s native scrollbar).
mouseWheel:{ deltaFactor: integer }
Set the number of pixels one wheel notch scrolls. The default value “auto” uses the OS/browser value.
mouseWheel:{ normalizeDelta: boolean }
Enable or disable mouse-wheel (delta) acceleration. Setting normalizeDelta: true translates mouse-wheel delta value to -1 or 1.
mouseWheel:{ invert: boolean }
Invert mouse-wheel scrolling direction. Set to true to scroll down or right when mouse-wheel is turned upwards.
mouseWheel:{ disableOver: [array] }
Set the tags that disable mouse-wheel when cursor is over them.
Default value:
["select","option","keygen","datalist","textarea"]
scrollButtons:{ enable: boolean }
Enable or disable scrollbar buttons.
scrollButtons:{ scrollAmount: integer }
Set the buttons scrolling amount (in pixels). The default value "auto" adjusts scrolling amount according to scrollable content length.
scrollButtons:{ scrollType: "string" }
Define the buttons scrolling type/behavior.

  • scrollType: "stepless" – continuously scroll content while pressing the button (default)
  • scrollType: "stepped" – each button click scrolls content by a certain amount (defined in scrollAmount option above)
scrollButtons:{ tabindex: integer }
Set a tabindex value for the buttons.
keyboard:{ enable: boolean }
Enable or disable content scrolling via the keyboard.
The plugin supports the directional arrows (top, left, right and down), page-up (PgUp), page-down (PgDn), Home and End keys.
keyboard:{ scrollAmount: integer }
Set the keyboard arrows scrolling amount (in pixels). The default value "auto" adjusts scrolling amount according to scrollable content length.
keyboard:{ scrollType: "string" }
Define the keyboard arrows scrolling type/behavior.

  • scrollType: "stepless" – continuously scroll content while pressing the arrow key (default)
  • scrollType: "stepped" – each key release scrolls content by a certain amount (defined in scrollAmount option above)
contentTouchScroll: integer
Enable or disable content touch-swipe scrolling for touch-enabled devices.
To completely disable, set contentTouchScroll: false.
Integer values define the axis-specific minimum amount required for scrolling momentum (default: 25).
documentTouchScroll: boolean
Enable or disable document touch-swipe scrolling for touch-enabled devices.
advanced:{ autoExpandHorizontalScroll: boolean }
Auto-expand content horizontally (for "x" or "yx" axis).
If set to true, content will expand horizontally to accommodate any floated/inline-block elements.
Setting its value to 2 (integer) forces the non scrollHeight/scrollWidth method. A value of 3 forces the scrollHeight/scrollWidth method.
advanced:{ autoScrollOnFocus: "string" }
Set the list of elements/selectors that will auto-scroll content to their position when focused.
For example, when pressing TAB key to focus input fields, if the field is out of the viewable area the content will scroll to its top/left position (same bahavior with browser’s native scrollbar).
To completely disable this functionality, set autoScrollOnFocus: false.
Default:
"input,textarea,select,button,datalist,keygen,a[tabindex],area,object,[contenteditable='true']"
advanced:{ updateOnContentResize: boolean }
Update scrollbar(s) automatically on content, element or viewport resize.
The value should be true (default) for fluid layouts/elements, adding/removing content dynamically, hiding/showing elements etc.
advanced:{ updateOnImageLoad: boolean }
Update scrollbar(s) automatically each time an image inside the element is fully loaded.
Default value is auto which triggers the function only on "x" and "yx" axis (if needed).
The value should be true when your content contains images and you need the function to trigger on any axis.
advanced:{ updateOnSelectorChange: "string" }
Update scrollbar(s) automatically when the amount and size of specific selectors changes.
Useful when you need to update the scrollbar(s) automatically, each time a type of element is added, removed or changes its size.
For example, setting updateOnSelectorChange: "ul li" will update scrollbars each time list-items inside the element are changed.
Setting the value to true, will update scrollbars each time any element is changed.
To disable (default) set to false.
advanced:{ extraDraggableSelectors: "string" }
Add extra selector(s) that’ll release scrollbar dragging upon mouseup, pointerup, touchend etc.
Example: extraDraggableSelectors: ".myClass, #myID"
advanced:{ releaseDraggableSelectors: "string" }
Add extra selector(s) that’ll allow scrollbar dragging upon mousemove/up, pointermove/up, touchend etc.
Example: releaseDraggableSelectors: ".myClass, #myID"
advanced:{ autoUpdateTimeout: integer }
Set the auto-update timeout in milliseconds.
Default timeout: 60
theme: "string"
Set the scrollbar theme.
View all ready-to-use themes
All themes are contained in plugin’s CSS file (jquery.mCustomScrollbar.css).
Default theme: "light"
callbacks:{
      onCreate: function(){}
}
A function to call when plugin markup is created.
Example:
callbacks:{
    onCreate:function(){
      console.log("Plugin markup generated");
    }
}
callbacks:{
      onInit: function(){}
}
A function to call when scrollbars have initialized (demo).
Example:
callbacks:{
    onInit:function(){
      console.log("Scrollbars initialized");
    }
}
callbacks:{
      onScrollStart: function(){}
}
A function to call when scrolling starts (demo).
Example:
callbacks:{
    onScrollStart:function(){
      console.log("Scrolling started...");
    }
}
callbacks:{
      onScroll: function(){}
}
A function to call when scrolling is completed (demo).
Example:
callbacks:{
    onScroll:function(){
      console.log("Content scrolled...");
    }
}
callbacks:{
      whileScrolling: function(){}
}
A function to call while scrolling is active (demo).
Example:
callbacks:{
    whileScrolling:function(){
      console.log("Scrolling...");
    }
}
callbacks:{
      onTotalScroll: function(){}
}
A function to call when scrolling is completed and content is scrolled all the way to the end (bottom/right) (demo).
Example:
callbacks:{
    onTotalScroll:function(){
      console.log("Scrolled to end of content.");
    }
}
callbacks:{
      onTotalScrollBack: function(){}
}
A function to call when scrolling is completed and content is scrolled back to the beginning (top/left) (demo).
Example:
callbacks:{
    onTotalScrollBack:function(){
      console.log("Scrolled back to the beginning of content.");
    }
}
callbacks:{
      onTotalScrollOffset: integer
}
Set an offset for the onTotalScroll option.
For example, setting onTotalScrollOffset: 100 will trigger the onTotalScroll callback 100 pixels before the end of scrolling is reached.
callbacks:{
      onTotalScrollBackOffset: integer
}
Set an offset for the onTotalScrollBack option.
For example, setting onTotalScrollBackOffset: 100 will trigger the onTotalScrollBack callback 100 pixels before the beginning of scrolling is reached.
callbacks:{
      alwaysTriggerOffsets: boolean
}
Set the behavior of calling onTotalScroll and onTotalScrollBack offsets.
By default, callback offsets will trigger repeatedly while content is scrolling within the offsets.
Set alwaysTriggerOffsets: false when you need to trigger onTotalScroll and onTotalScrollBack callbacks once, each time scroll end or beginning is reached.
callbacks:{
      onOverflowY: function(){}
}
A function to call when content becomes long enough and vertical scrollbar is added.
Example:
callbacks:{
    onOverflowY:function(){
      console.log("Vertical scrolling required");
    }
}
callbacks:{
      onOverflowX: function(){}
}
A function to call when content becomes wide enough and horizontal scrollbar is added.
Example:
callbacks:{
    onOverflowX:function(){
      console.log("Horizontal scrolling required");
    }
}
callbacks:{
      onOverflowYNone: function(){}
}
A function to call when content becomes short enough and vertical scrollbar is removed.
Example:
callbacks:{
    onOverflowYNone:function(){
      console.log("Vertical scrolling is not required");
    }
}
callbacks:{
      onOverflowXNone: function(){}
}
A function to call when content becomes narrow enough and horizontal scrollbar is removed.
Example:
callbacks:{
    onOverflowXNone:function(){
      console.log("Horizontal scrolling is not required");
    }
}
callbacks:{
      onBeforeUpdate: function(){}
}
A function to call right before scrollbar(s) are updated.
Example:
callbacks:{
    onBeforeUpdate:function(){
      console.log("Scrollbars will update");
    }
}
callbacks:{
      onUpdate: function(){}
}
A function to call when scrollbar(s) are updated.
Example:
callbacks:{
    onUpdate:function(){
      console.log("Scrollbars updated");
    }
}
callbacks:{
      onImageLoad: function(){}
}
A function to call each time an image inside the element is fully loaded and scrollbar(s) are updated.
Example:
callbacks:{
    onImageLoad:function(){
      console.log("Image loaded");
    }
}
callbacks:{
      onSelectorChange: function(){}
}
A function to call each time a type of element is added, removed or changes its size and scrollbar(s) are updated.
Example:
callbacks:{
    onSelectorChange:function(){
      console.log("Scrollbars updated");
    }
}
live: "string"
Enable or disable applying scrollbar(s) on all elements matching the current selector, now and in the future.
Set live: true when you need to add scrollbar(s) on elements that do not yet exist in the page. These could be elements added by other scripts or plugins after some action by the user takes place (e.g. lightbox markup may not exist untill the user clicks a link).
If you need at any time to disable or enable the live option, set live: "off" and "on" respectively.
You can also tell the script to disable live option after the first invocation by setting live: "once".
liveSelector: "string"
Set the matching set of elements (instead of the current selector) to add scrollbar(s), now and in the future.

Plugin methods

Ways to execute various plugin actions programmatically from within your script(s).

update

Usage $(selector).mCustomScrollbar("update");

Call the update method to manually update existing scrollbars to accommodate new content or resized element(s). This method is by default called automatically by the script (via updateOnContentResize option) when the element itself, its content or scrollbar size changes.

view examples

/* initialize plugin with auto-update options disabled */
$(selector).mCustomScrollbar({
  advanced:{
    updateOnContentResize: false,
    updateOnImageLoad: false
  }
});

/* at some point in your js script/code update scrollbar manually */
$(selector).mCustomScrollbar("update");

scrollTo

Usage $(selector).mCustomScrollbar("scrollTo",position,options);

Call the scrollTo method to programmatically scroll the content to the position parameter (demo).

position parameter

Position parameter can be:

  • "string"
    • e.g. element selector: "#element-id"
    • e.g. special pre-defined position: "bottom"
    • e.g. number of pixels less/more: "-=100"/"+=100"
  • integer
    • e.g. number of pixels: 100
  • [array]
    • e.g. different y/x position: [100,50]
  • object/function
    • e.g. jQuery object: $("#element-id")
    • e.g. js object: document.getelementbyid("element-id")
    • e.g. function: function(){ return 100; }

Pre-defined position strings:

  • "bottom" – scroll to bottom
  • "top" – scroll to top
  • "right" – scroll to right
  • "left" – scroll to left
  • "first" – scroll to the position of the first element within content
  • "last" – scroll to the position of the last element within content

view examples

Scroll to element with id “#el-1″

$(selector).mCustomScrollbar("scrollTo","#el-1");

Scroll to top

$(selector).mCustomScrollbar("scrollTo","top");

Scroll by 100 pixels down or right

var val=100;
$(selector).mCustomScrollbar("scrollTo","-="+val);

Scroll by 100 pixels up or left

$(selector).mCustomScrollbar("scrollTo","+=100");

Scroll by 100 pixels down and by 50 pixels right

$(selector).mCustomScrollbar("scrollTo",["-=100","-=50"]);

Scroll to the fifth paragraph

$(selector).mCustomScrollbar("scrollTo",$("p:eq(4)"));

Scroll to the last element within your content

$(selector).mCustomScrollbar("scrollTo","last");

Scroll to some variable value

var val=document.getelementbyid("element-id");
$(selector).mCustomScrollbar("scrollTo",val);

Scroll to 300 pixels

$(selector).mCustomScrollbar("scrollTo",300);

Method options

scrollInertia: integer
Scroll-to duration, value in milliseconds.
Example:
$(selector).mCustomScrollbar("scrollTo","bottom",{
    scrollInertia:3000
});
scrollEasing: "string"
Scroll-to animation easing, values: "linear", "easeOut", "easeInOut".
Example:
$(selector).mCustomScrollbar("scrollTo","bottom",{
    scrollEasing:"easeOut"
});
moveDragger: boolean
Scroll scrollbar dragger (instead of content).
Example:
$(selector).mCustomScrollbar("scrollTo",80,{
    moveDragger:true
});
timeout: integer
Set a timeout for the method (the default timeout is 60 ms in order to work with automatic scrollbar update), value in milliseconds.
Example:
$(selector).mCustomScrollbar("scrollTo","top",{
    timeout:1000
});
callbacks: boolean
Trigger user defined callbacks after scroll-to completes.
Example:
$(selector).mCustomScrollbar("scrollTo","left",{
    callbacks:false
});

stop

Usage $(selector).mCustomScrollbar("stop");

Stops any running scrolling animations (usefull when you wish to interupt a previously scrollTo method call).

disable

Usage $(selector).mCustomScrollbar("disable");

Calling disable method will temporarily disable the scrollbar (demo). Disabled scrollbars can be re-enable by calling the update method.

To disable the scrollbar and reset its content position, set the method’s reset parameter to true

$(selector).mCustomScrollbar("disable",true);

view examples

/* initialize plugin */
$(selector).mCustomScrollbar();

/* at some point in your js script/code disable scrollbar */
$(selector).mCustomScrollbar("disable");

/* re-enable scrollbar as needed */
$(selector).mCustomScrollbar("update");

destroy

Usage $(selector).mCustomScrollbar("destroy");

Calling destroy method will completely remove the custom scrollbar and return the element to its original state (demo).

view examples

/* initialize plugin */
$(selector).mCustomScrollbar();

/* at some point in your js script/code destroy scrollbar */
$(selector).mCustomScrollbar("destroy");

Scrollbar styling & themes

You can design and visually customize your scrollbars with pure CSS, using jquery.mCustomScrollbar.css which contains the default/basic styling and all scrollbar themes.

The easiest/quickest way is to select a ready-to-use scrollbar theme. For example:

$(selector).mCustomScrollbar({
  theme:"dark"
});

View all ready-to-use themes

You can modify the default styling or any theme either directly in jquery.mCustomScrollbar.css or by overwriting the CSS rules in another stylesheet.

Creating a new scrollbar theme

Create a name for your theme (e.g. “my-theme”) and set it as the value of the theme option

$(selector).mCustomScrollbar({
    theme:"my-theme"
});

Your element will get the class “mCS-my-theme” (your theme-name with “mCS” prefix), so you can create your CSS using the .mCS-my-theme in your rules. For instance:

.mCS-my-theme.mCSB_scrollTools .mCSB_dragger .mCSB_dragger_bar{ background-color: red; }
.mCS-my-theme.mCSB_scrollTools .mCSB_draggerRail{ background-color: white; } 
/* and so on... */

In the same manner you can clone any existing theme (e.g. “dark”), change its selector (e.g. .mCS-dark) to your own theme name (e.g. .mCS-my-theme) and modify its CSS rules.

Scrollbar markup

The plugin applies specific id (unique) and/or classes to every scrollbar element/component, meaning that you can target and modify any scrollbar in more than one ways.

For example, every element with a scrollbar gets a unique class in the form of _mCS_1, _mCS_2 etc. Every scrollbar container element gets a unique id in the form of mCSB_1_scrollbar_vertical, mCSB_2_scrollbar_vertical etc. Every scrollbar dragger gets a unique id in the form of mCSB_1_dragger_vertical, mCSB_2_dragger_vertical etc. in addition to the class mCSB_dragger. All these mean that you can do stuff like:

._mCS_1 .mCSB_dragger .mCSB_dragger_bar{ background-color: red; }

._mCS_2 .mCSB_dragger .mCSB_dragger_bar{ background-color: green; }

#mCSB_3_dragger_vertical .mCSB_dragger_bar{ background-color: blue; }

#mCSB_1_scrollbar_vertical .mCSB_dragger{ height: 100px; }

#mCSB_1_scrollbar_horizontal .mCSB_dragger{ width: 100px; }

.mCSB_1_scrollbar .mCSB_dragger .mCSB_draggerRail{ width: 4px; }

Custom scrollbar layout

User-defined callbacks

You can trigger your own js function(s) by calling them inside mCustomScrollbar callbacks option parameter

$(".content").mCustomScrollbar({
    callbacks:{
        onScroll:function(){
            myCustomFn(this);
        }
    }
});

function myCustomFn(el){
    console.log(el.mcs.top);
}

In the example above, each time a scroll event ends and content has stopped scrolling, the content’s top position will be logged in browser’s console. There are available callbacks for each step of the scrolling event:

  • onScrollStart – triggers the moment a scroll event starts
  • whileScrolling – triggers while scroll event is running
  • onScroll – triggers when a scroll event completes
  • onTotalScroll – triggers when content has scrolled all the way to bottom or right
  • onTotalScrollBack – triggers when content has scrolled all the way back to top or left

You can set an offset value (pixels) for both onTotalScroll and onTotalScrollBack by setting onTotalScrollOffset and onTotalScrollBackOffset respectively (view example).

The following will trigger the callback function when content has scrolled to bottom minus 100 pixels

$(".content").mCustomScrollbar({
    callbacks:{
        onTotalScroll:function(){
            console.log("scrolled to bottom");
        },
    onTotalScrollOffset:100
    }
});

By default, onTotalScroll and onTotalScrollBack callbacks are triggered repeatedly. To prevent multiple calls when content is within their offset, set alwaysTriggerOffsets option to false (view example).

$(".content").mCustomScrollbar({
    callbacks:{
        onTotalScroll:function(){
            console.log("scrolled to bottom");
        },
    onTotalScrollOffset:100,
    alwaysTriggerOffsets:false
    }
});

Additional callbacks:

Returning values

The script returns a number of values and objects related to scrollbar that you can use in your own functions

  • this – the original element containing the scrollbar(s)
  • this.mcs.content – the original content wrapper as jquery object
  • this.mcs.top – content’s top position (pixels)
  • this.mcs.left – content’s left position (pixels)
  • this.mcs.draggerTop – scrollbar dragger’s top position (pixels)
  • this.mcs.draggerLeft – scrollbar dragger’s left position (pixels)
  • this.mcs.topPct – content vertical scrolling percentage
  • this.mcs.leftPct – content horizontal scrolling percentage
  • this.mcs.direction – content’s scrolling direction (y or x)

view examples

Load more content when scrolled to bottom

$(selector).mCustomScrollbar({
    callbacks:{
        onTotalScroll:function(){
            this.mcs.content.append("...");
        }
    }
});

Run code when at least half of the content is scrolled

$(selector).mCustomScrollbar({
    callbacks:{
        whileScrolling:function(){
            var pct=this.mcs.topPct;
            if(pct>=50){
              /* do something... */
            }
        }
    }
});

Plugin-specific jQuery expressions

$("#myID:mcsInView")
Select element(s) in your content that are within scrollable viewport.
As condition: $("#myID").is(":mcsInView");
$(".content:mcsOverflow")
Select overflowed element(s) with visible scrollbar.
As condition: $(".content").is(":mcsOverflow");
$("#myID:mcsInSight")
$("#myID:mcsInSight(exact)")
Select element(s) in your content that are in view of the scrollable viewport. Using the exact parameter will include elements that have any part of them (even 1 pixel) in view of the scrollable viewport.
As condition: $("#myID").is(":mcsInSight");, $("#myID").is(":mcsInSight(exact)");

Plugin dependencies & requirements

License

This work is released under the MIT License.
You are free to use, study, improve and modify it wherever and however you like.
https://opensource.org/licenses/MIT

Pages: 1 2 3 4


5,630 Comments

Post a comment

Comments pages: 1 17 18 19 20 21 85

  1. Shane Waugh
    Posted on September 14, 2012 at 03:36 Permalink

    hi…

    I’ve implemented your scripts into my test site on BC and it’s scrolling but i can’t work out why it’s not picking up the styling. It’s only picking up the standard scroll bar…

    Can you point out what i need to change, if anything.

    p.s. Great scrollers!!!

    cheers
    Shane Waugh

    Reply
  2. Michal Bulla
    Posted on September 14, 2012 at 00:04 Permalink

    Hi there, I’m trying to implement this scrollbar, but it’s not working. I did everything – included all files, I calles the function and nothing.

    Here is the link: http://ip-studio.sk/test

    Please help!
    Thank you.

    Reply
    • malihu
      Posted on September 14, 2012 at 02:03 Permalink

      You’ve set media="print" on the link to the jquery.mCustomScrollbar.css:
      <link href="/cms/content/themes/custom/Site/stylesheets/jquery.mCustomScrollbar.css" rel="stylesheet" type="text/css" media="print" />
      which means the CSS doesn’t load. Just remove it:
      <link href="/cms/content/themes/custom/Site/stylesheets/jquery.mCustomScrollbar.css" rel="stylesheet" type="text/css" />
      or add “screen” as the value if you need the attribute.

      Reply
      • Michal Bulla
        Posted on September 14, 2012 at 10:35 Permalink

        Oh, thanks a lot 😉

        Reply
  3. Milen
    Posted on September 13, 2012 at 18:41 Permalink

    Hello! Great scrollbar! I really enjoy it. But i have one question:
    I want the scroller into one box in the web site (where the content is) but I want to be able scroll with the mouse from the all web site, not only from the box. Is it possible?
    Thanks!

    Reply
    • malihu
      Posted on September 14, 2012 at 02:22 Permalink

      Not really. The mouse-wheel event binds on .mCustomScrollBox. That said, you could achieve what you need by manipulating .mCSB_container and .mCSB_scrollTools dimensions and/or position within the CSS. That of course depends heavily on the rest of your page layout.

      Reply
  4. Stefano
    Posted on September 13, 2012 at 18:09 Permalink

    I really appreciate your works!
    I used that in a div centred in the middle of the page.
    I ask you if there’s any way to continue the scrolling action after being arived at the bottom of the div (but, ofcourse, not at the end of the page -> the page still can be scrolled for some length).
    Tanks a lot for any replies.
    Stefano

    Reply
    • malihu
      Posted on September 14, 2012 at 02:11 Permalink

      I see what you mean. Currently there’s no way for such mouse-wheel behavior. I’ll need to work on that and see how I can implement it in the plugin. Thanks for the feedback.

      Reply
      • Stefano
        Posted on September 14, 2012 at 14:02 Permalink

        Thanks a lot!

        Reply
  5. stephen
    Posted on September 13, 2012 at 14:42 Permalink

    I”m having an issue fading divs on scroll.

    In want to fade divs when I move this scrollbar. I’d like them to instantly fade out when there is a change on the scroller and then fade back in.
    Also I’d like to stop this function from happening on the .stop event for the scroller

    Reply
    • malihu
      Posted on September 14, 2012 at 02:34 Permalink

      If I understand correctly, you cannot do that as there’s only one onScroll callback which runs when a single scroll is completed. For what you need, it would require an onScrollStart and an onScrollEnd callbacks which I’m not sure is possible to implement. Moreover it would greatly affect performance, especially when fading in and out content every few milliseconds.

      Reply
  6. Don
    Posted on September 12, 2012 at 07:27 Permalink

    Is there a way to set the scrollbar so that it’s always visible? Right now, I’m trying to use the scrollbar with some expanding content. The problem is that the collapsed content isn’t large enough to activate the scrollbar when the page first loads. And when the content does expand, it fails to activate the scrollbar after the fact. Thoughts?

    Reply
    • malihu
      Posted on September 12, 2012 at 09:34 Permalink

      You need to call the update method of the plugin after your content is expanded (and is long enough to need a scrollbar).
      Example: $(".content").mCustomScrollbar("update");

      For more info and working examples please read “Plugin methods: update”. You may also find related info in “Configuration” and “Additional info” sections of the post.

      Reply
  7. SHiN
    Posted on September 11, 2012 at 14:39 Permalink

    hi,

    how can i use this plugin with fancybox
    i want to change scrollbar in fancybox

    Thankyou 🙂

    Reply
    • malihu
      Posted on September 11, 2012 at 15:31 Permalink

      I cannot really provide specific instructions for using the plugin on markup generated by other scripts, plugins or applications. The implementation guide is the same for any element you want to add custom scrollbar. You probably need to find the overflow:auto div generated by fancybox and call mCustomScrollbar function on it.

      Reply
      • SHiN
        Posted on September 12, 2012 at 08:50 Permalink

        hi

        i got it.
        Thank you so much for your reply.

        Thank you 🙂

        Reply
  8. Chip Cheezum
    Posted on September 11, 2012 at 07:56 Permalink

    Hi, I’m using this in my site http://chipandironicus.com/ , but I’m having a few problems. It appears to work fine in Chrome, Safari, and Firefox, but I’m having problems with it in Internet Explorer 9 and Opera. In IE9, sometimes the scrollbar never appears and/or the content in the div overflows onto the rest of the site. This is seemingly random and I can’t get it to happen consistently, but it happens enough that it’s a problem. Sometimes it gets fixed if you refresh it a lot. The scroll bar seems to disappear more often if you are on a video page like this one: http://chipandironicus.com/videos/condemned/1.html and click the X button to go back to the index. Sometimes the content won’t overflow its div, but the scrollbar will still not appear. This also appears to be random.

    The problem in Opera is a little different. If I am on a page with the scrollbar and click on a link that takes me to another page with a scrollbar, it’s fine. But if I then click the browser’s back button, the previous page will not have the scroll bar and the content will again overflow. The scrollbar is fine if you click on a link that takes you to the page, it only breaks when you click on the browser’s back button.

    I’m not much of a coder so I can’t quite figure out what’s going on, but is there something wrong with the way I’m calling the scripts? For both Internet Explorer and Opera it seems like the problem is that the scripts aren’t being loaded.

    Reply
    • malihu
      Posted on September 11, 2012 at 12:33 Permalink

      Hi,

      I cannot reproduce the issue regarding browser’s back button on Opera (version 12.02). I checked your pages with IE9 developer tools and I get “‘mCustomScrollbars’ is undefined” error (inside document ready, you’re calling mCustomScrollbars() which does not exist). Try removing it as it might break your pages. I also get more than one js errors when I click the close button of the video (probably video player errors).

      Reply
  9. Erwin
    Posted on September 11, 2012 at 01:48 Permalink

    That’s an amazing plugin!
    Anyway, I need to get the width set by the plugin.
    I’ve been using the plugin in a table which is responsive, so when it increase horizontally (resizing the browser), it “stop” increasing when the initial width set by the plugin is reached.
    For instance, my initial screen is 1024 x 800 and my table is 1400px, the plugin set the width of his content in 1400px and applies properly scroll (all right so far). But when my screen increase horizontally (1800px for example) the table doesn’t seem to responde to it and stop when it reachs 1400px and a wasted space (400px) on the right appears.
    I’m starting with Jquery and I find that if the plugin applies min-width instead width to the container, it would be perfect. Or if it’s not possible, then how can I get the width set by the plugin.

    Sorry if my english is not good enough 🙂 But it’s not my native language.
    Thanks!

    Reply
  10. Gustav
    Posted on September 11, 2012 at 00:07 Permalink

    Hi!

    I’m currently using your plugin on a website. Everything works great except in chrome on windows. There I get a wierd scrolling effect (the content “bounces back”) and sometimes the content will get a “position:left” of several million putting the content way off the browser window.
    See here for an example: http://marico-design.com/portfolio/category/design/

    Any ideas?

    Thanks for a great plugin!

    Reply
    • malihu
      Posted on September 11, 2012 at 00:58 Permalink

      Hi,

      I can’t seem to reproduce the bouncing-back scrolling. I checked your page on Chrome version 21 (21.0.1180.89) on Windows 7 and scrolling (as well as the hover effects inside it) are very smooth.

      Reply
      • Gustav
        Posted on September 11, 2012 at 01:13 Permalink

        Thanks for the quick reply.

        I found out what was causing it… My stupid mistake.
        Chrome was slightly zoomed in ( 110% zoom ). As soon as I changed that it worked great there too.

        Reply
  11. Lennie Moore
    Posted on September 9, 2012 at 23:19 Permalink

    So everything’s coming together pretty well with this plugin. I’ve got it working with scrolling, scrollbuttons, and also added up/down cursors doing the same thing as the scroll buttons on this page:
    Credits

    Anyone wanting similar functionality, feel free to steal from my page 🙂

    I’m now working on my blog page, where I want to have anchor links in my .sidebar div that will have the scroller scrollto each blog post but I must be not understanding how to do this properly. I’ve tried the js code in Simon Dau’s ,a href=”http://www.blog.kartogram.co.uk/post.cfm/custom-functionality-for-custom-scrollbar”>page but am having trouble.

    You can see how I originally had it working using jquerytools here:
    Old Blog
    With this toolset I was able to just have my anchors in a typical html format (located in my .sidebar div) and the content would jump to the right place.

    Where I’m at now:
    Test Blog

    The functionality I’m needing is:
    1. scrollto anchors residing in the .sidebar with a naming convention of #itemnnn where nnn=numbers from 000-999 (allowing for lots of content obviously). Example would be #item123
    2. scrollto next and prev buttons which could be located either in the .content window or the .sidebar (not sure which way I’ll go here). This method would be for jumping to the next item no matter what number it is on a page such as my News page.

    Any help would be tremendously appreciated. I’m so close to having the infrastructure solid here this would mean I can finally launch my site soon!

    Reply
    • malihu
      Posted on September 10, 2012 at 01:17 Permalink

      Hi again Lennie,

      Simon Dau’s code is an awesome extension for the previous version (1.0) of the plugin. On the current version (2), which is the one you’re using, I’ve implemented a pretty versatile scrollTo method that allows you to do what you describe.

      You may need to read the “Plugin methods: ScrollTo” section on the post that explains how to use it to scroll-to any specific position within your content.
      In short, you can do something like:

      $("#yourLinkID").click(function(e){ e.preventDefault(); $(".content").mCustomScrollbar("scrollTo","#item123"); });

      On the example above, when the #yourLinkID is clicked, the custom scrollbar will scroll-to the position of #item123 element inside your .content.

      For the next/previous links, you should probably add a script that finds the next element to scroll-to (e.g. using jQuery $.next() function) and change ScrollTo target accordingly (same with previous).

      Your links can be anywhere in your document (inside or outside the element with the custom scrollbar).

      Reply
      • Lennie Moore
        Posted on September 10, 2012 at 03:22 Permalink

        Cool, thx. I’ll get to work on this.

        Reply
      • Lennie Moore
        Posted on September 10, 2012 at 10:21 Permalink

        Progress. It’s scrolling to each blog post (thank you for the help!) but for some reason it’s not scrolling consistently to the h2 titles. They drift a bit in their location.

        Check it out here.

        Is it something in one of my scrollAmount settings? Or is it something else? Strange…

        Reply
        • Lennie Moore
          Posted on September 10, 2012 at 20:11 Permalink

          I used a half-baked workaround for now by inserting ” ” spacers at the end of each blog to get it close to what I need. Not an elegant hack.

          It’d be good to know why the scrollto is not consistently going to the right location.

          Reply
        • malihu
          Posted on September 11, 2012 at 00:28 Permalink

          The slightly off scrolling to headings position, happens probably because of the way CSS handles element margins that overflow their container.

          Try removing
          <a id="item008"></a>
          and add those ids on your divs. For example:
          <div id="item008"> <div class="blogitem"> ... </div> </div>
          or
          <div> <div id="item008" class="blogitem"> ... </div> </div>

          There are a few things you can also try like giving .blogitem and/or its parent divs overflow:hidden, “playing” with position:relative on the anchors and divs etc. but I think the above will fix any scroll-to position issues.

          Reply
          • Lennie Moore
            Posted on September 11, 2012 at 04:13 Permalink

            bummer. none of this seems to work. I did change the ids to the divs that makes more sense. Been tweaking the css and looking for the culprit but have found nothing so far.

            btw thank you for the time in helping me on this. If you look on my blog on the “About This Website” post you’ll notice I’m going to be giving you a serious plug.

            current blog page

          • malihu
            Posted on September 11, 2012 at 13:06 Permalink

            Can’t thank you enough 🙂

  12. Bigorangemachine
    Posted on September 7, 2012 at 18:25 Permalink

    Love the plugin!
    Small issue
    If you use ‘scrollTo’ hook and use an int of 0; than it won’t scroll.

    in jquery.mCustomScrollbar.js
    Line 600 needs to be changed
    if(scrollTo){
    to
    if(typeof(scrollTo)!=’undefined’){
    or
    if(typeof(scrollTo)==’string’ || typeof(scrollTo)==’number’){

    Reply
    • malihu
      Posted on September 7, 2012 at 18:36 Permalink

      Yes, instead of 0, use “top” (or “left” for horizontal scrollbar).

      Reply
  13. David
    Posted on September 7, 2012 at 18:07 Permalink

    Great plugin, sir. Excellent documentation. I am using it on my blog but maybe I will be able to use it for work one day if I get another web development project.

    Reply
  14. Baraneedharan
    Posted on September 7, 2012 at 15:59 Permalink

    Hello,

    I have container whose height is say 400 and overflow hidden. I also have a READ MORE button. When i click on read more i am enabling the plugin. Likewise i need to disable the plugin when i click READ LESS. Can it be achievable ?? Please help . Thanks in advance 🙂

    Reply
    • malihu
      Posted on September 7, 2012 at 17:56 Permalink

      You can increase or decrease your content height each time you click “read more” and “read less” accordingly. When your content is shorter than its container then the scrollbar is disabled (as no scrolling is needed). After plugin initiates, your original content resides within the .mCSB_container div (this div has by default overflow:hidden). Changing its height will do what you need.

      Reply
  15. Will
    Posted on September 7, 2012 at 01:57 Permalink

    Hi dude. I have a modal and a button on the site. if i click the button, the modal shows up. inside the modal, there’s the div i want the scrollbar to show up. However, pressing the button doubles the scrollbar. Any fix for this?

    $("a[rel='show-content']").click(function(e){ e.preventDefault(); $("#content_1").fadeToggle("slow",function(){ var customScrollbar=$("#content_1").find(".mCSB_scrollTools"); customScrollbar.css({"opacity":0}); $("#content_1").mCustomScrollbar("update"); customScrollbar.animate({opacity:1},"slow"); }); });

    I’ve been experimenting for 5 hours straight. 😀

    $("#content_1").mCustomScrollbar();
    that code gives the div the scrollbar, is there a reverse way for this? Thanks in advance sir!

    Reply
    • malihu
      Posted on September 7, 2012 at 04:04 Permalink

      Hello,

      I’m guessing you’re calling $("#content_1").mCustomScrollbar(); before your click event function, correct? When you say doubles the scrollbar, you mean you get 2 scrollbars?

      Can you send me a link to check the code? I can’t really be much help otherwise.

      Reply
  16. chris
    Posted on September 6, 2012 at 13:46 Permalink

    Very inspiring to me. It brings some Ideas to my mind.

    Since I’m not a coder, just a Foto/Video Guy – may I ask possibly dumb questions?

    like:
    Performance- and functionional- wise, where to place the js-Scripts best in a WordPress-Theme? Globally? Like in the Header for the whole Page anytime?

    Or better within in the Articles just where I want them?

    and better than educate everybody:
    🙂 Couldn’d you “just” make a WP-Plugin with Shortcode-support for dumb folks like mine? I wouldn’t mind paying/donating for such. You seem capable!

    Reply
    • malihu
      Posted on September 6, 2012 at 18:28 Permalink

      Hi Chris,

      Depends on how often you’ll use the plugin in your WordPress and if you already have jQuery and jQuery UI loaded in your header or functions.php.

      If you only plan on using it on some widget or specific page and you don’t need jQuery UI for other plugins, then you should probably include it only on the templates you want.

      If you already using jQuery (and especially jQuery UI) for other plugins and/or plan to use the plugin often on any article, then you should include it in your header or functions.php.

      jQuery is included by default in latest WordPress, so if you already use jQuery UI then the rest of the plugin files are something like 25kb, no big deal on loading times.

      Another way would be to create 2 templates for your theme. One without the plugin and one with it. This way you could easily select the template you want for each of your posts, according to its content.

      I’ll probably release a WordPress plugin at some point. I just need the new plugin version to be implemented and used as much as possible so I can get feedback and fix any errors or make additions before I release it for WordPress.

      It doesn’t seem much work at first, but each time I change code, I need to update local files, remote files, github etc. Add WordPress repository and multiply by x number of plugins and it adds up very quickly! That’s why I try to go slowly and avoid releasing jQuery and WordPress plugins at the same time.

      Reply
      • Chris
        Posted on September 11, 2012 at 13:34 Permalink

        Thank you for your time answering me!

        And thank you for the suggestions. I’ve put it in the functions.php. My longtime Goal is a compact Onepage Portfolio with a Slider Window per Article for Pictures/Video avoiding too deep Navigation and those Modal Windows (wich I find often too slow and irritating as a Userexperience)

        I understand that it is a lot of work! Just wanted to let you know that it is much apreciated. And also thank’s for the good documentation. I personally may not be able to understand everything but that’s my learning curve now 🙂

        And as I sayd: allthough I appreciate Free Software (and OpenSource Concepts in particular for Core Technologies) I shurely would spend some money on a convenience-raising Backend User Interface that enables me being creative without going into much coding (or finding and hiring a dedicated Programmer for it). For instance like shortcodes for the TinyMCE to embed the Customscrollbar with different options, choosable or custom uploadable graphics, automatic theme setup…

        but maybe i’ll learn some more html/css/js – it looks interesting.

        All the Best, Chris

        Reply
  17. Marc-Andre Cote
    Posted on September 6, 2012 at 01:55 Permalink

    Hi, is it possible to make a scrollTo with choosing coordinate like : scrollTo_x and scrollTo_y?
    Actually, I was able to scroll verticaly with a integer value but not horizontaly…

    Reply
    • malihu
      Posted on September 6, 2012 at 18:42 Permalink

      Hi,

      You cannot scroll to position horizontally and vertically at the same time, since the plugin does not support scrollbars for both axis on a single element.

      Reply
  18. James Endersby
    Posted on September 5, 2012 at 17:42 Permalink

    Hi,

    Great code. However I have noticed that the custom scrollbars do not show up on tablet PC or iPads.
    Is their a correction for this?

    Many thanks

    Mediagrin

    Reply
    • malihu
      Posted on September 6, 2012 at 18:38 Permalink

      Hi,

      I’ve intentionally avoided using custom scrollbars on touch devices cause I don’t want to mess with usability and the way users scrolling.

      The plugin checks for touch devices and applies overflow: auto css rules, as well as -webkit-overflow-scrolling: touch to the content block so it can be scrolled natively by swiping.

      Reply
      • James Endersby
        Posted on September 6, 2012 at 20:14 Permalink

        Fair play and that makes sense.
        Thanks for your replay.

        Reply
  19. Pinto
    Posted on September 5, 2012 at 13:38 Permalink

    I, thx for u’r script, he is very amazing.

    But I want apply-it for scroollbar left! with the direction=”rtl” he won’t work it at left.

    How I can do ?

    Thx

    Reply
    • malihu
      Posted on September 5, 2012 at 16:30 Permalink

      You can set the scrollbar on the left of your content by changing the position of .mCustomScrollBox .mCSB_scrollTools within the jquery.mCustomScrollbar.css. You’d also need to set a left-margin for the .mCSB_container. For example:
      .mCSB_container{ width:auto; margin-left:30px; overflow:hidden; } .mCSB_container.mCS_no_scrollbar{ margin-left:0; } .mCustomScrollBox .mCSB_scrollTools{ width:16px; height:100%; top:0; left:0; }

      Reply
      • Pinto
        Posted on September 5, 2012 at 17:28 Permalink

        It’s working, thank’s for all. =)

        Reply
  20. JSirius
    Posted on September 3, 2012 at 17:59 Permalink

    Hello,

    I’m using your script to scroll a list and when I switch stylesheet with :
    $("link[rel=stylesheet]").attr("href",$(this).attr('rel'));

    After used the switcher, the scroolbar disappears and the list scroll to the last item. Then I can’t use the mouse or drag’n’drop…

    I try to use update method after switch, but it doesn’t work!

    Thank in advance…

    Best Regards
    Julien

    Reply
    • malihu
      Posted on September 4, 2012 at 14:47 Permalink

      I can’t really know where the problem could be. Can you post a link so I can check it?

      Reply
      • JSirius
        Posted on September 4, 2012 at 15:25 Permalink

        Hello,

        You can download my project here : http://dl.free.fr/fCR6xcUgb
        Open “index.htm” and click on “Theme 1” and “Theme 2” to switch CSS.
        I use your script for the left side.
        In the file :
        – L.98 : code to switch css
        – L.143 : transform to mCustomScrollbar

        Thank you to have respond!
        Julien

        Reply
      • JSirius
        Posted on September 4, 2012 at 15:51 Permalink

        I made you a smaller projet :
        http://dl.free.fr/qEZicY5GK

        Reply
  21. Lennie Moore
    Posted on September 3, 2012 at 08:44 Permalink

    Cool plugin! Lots of potential for what I can use on my website.

    I’m having a problem (mostly because I’m a composer and NOT a javascript programmer) getting the plugin to work. I can access the plugin fine and customize how it’s looking but my content disappears as soon as I use the scrollbar or mousewheel? Not sure what that’s about. I also can not access the arrow images from your png file.

    Any help would be appreciated. My test web page for this is:
    http://www.lenniemoore.com/credits_test.html

    Thanks!

    Reply
    • malihu
      Posted on September 3, 2012 at 14:26 Permalink

      Hi,

      It seems that you’ve hard-coded the custom scrollbar markup, which the plugin creates automatically. Your content markup should only have your own content. For example in your page it should be:

      <article class="substance"> <section id="scrolltext"> <div class="content"> <div class="item"> ... </div> <div class="item"> ... </div> <div class="item"> ... </div> </div> </section> </article>

      You don’t need to insert any of the divs that have to do with the scrollbar. The script does everything else.

      Reply
      • Lennie Moore
        Posted on September 3, 2012 at 17:58 Permalink

        Awesome. I knew it was something stupid on my end. I misunderstood the html examples above.

        Thanks for saving a composers life.

        Reply
        • malihu
          Posted on September 3, 2012 at 20:04 Permalink

          Firstly thanks a lot for your donation. It greatly helps me focus on creating and supporting free software.

          Off-topic:
          When I checked the code on your page I was, as usual, seeing only the code… I didn’t notice you’re the composer of such awesome music until I took a more “relaxed” look and saw Outcast video game on the list!
          Oh man! I loved your work on Outcast and I cannot even express myself on how much I absolutely love Watchmen motion comic OST. Seriously, I’m a big fan of your music.

          Thanks for being a composer 🙂

          Reply
          • Lennie Moore
            Posted on September 4, 2012 at 21:22 Permalink

            LOL Thanks for the kind words and for making such a great plugin. I’m happy to donate to the cause.

            I’m still trying to figure out why I don’t see any scroll button arrows from the .png file. I’ve put it in several directories on my server just in case the plug is looking in a particular location but I think the problem is somewhere in how I coded either the js or html. I probably have to turn something on eh?

            $(window).load(function() { $(".content").mCustomScrollbar({ set_width:true, set_height:true, horizontalScroll:false, scrollInertia:660, scrollEasing:"easeOutQuart", mouseWheel:"auto", autoDraggerLength:true, scrollButtons:{ enable:true, scrollType:"pixels", scrollSpeed:80, scrollAmount:302 }, advanced:{ updateOnBrowserResize:true, updateOnContentResize:true, autoExpandHorizontalScroll:false }, callbacks:{ onScroll:function(){}, onTotalScroll:function(){}, onTotalScrollOffset:0 } }); });// $avaScript Document

          • Lennie Moore
            Posted on September 4, 2012 at 22:39 Permalink

            Figured it out. I didn’t have the css correct.

            You should also consider adding the following comments into the css file:

            .mCSB_scrollTools .mCSB_buttonUp{ background-position:96px,0; /* buttonUp locations are 0 0/16px 0/32px 0/48px 0 (white) and 80px 0/96px 0/112px 0/128px 0 (black) */ } .mCSB_scrollTools .mCSB_buttonDown{ bottom: 0px; background-position:96px -20px; /* buttonDown locations are 0 -20px/16px -20px/32px -20px/48px -20px (white) and 80px -20px/96px -20px/112px -20px/128px -20px (black) */ } .mCSB_scrollTools .mCSB_buttonLeft{ background-position:100px -40px; /* buttonLeft locations are 0 -40px/20px -40px/40px -40px/60px -40px (white) and 80px -40px/100px -40px/120px -40px/140px -40px (black) */ } .mCSB_scrollTools .mCSB_buttonRight{ background-position:100px -56px; /* buttonRight locations are 0,-56px/20px -56px/40px -56px/60px -56px (white) and 80px -56px/100px -56px/120px -56px/140px -56px (black) */ }

          • Lennie Moore
            Posted on September 4, 2012 at 23:36 Permalink

            Oops! Ignore that last note. I listed the wrong coordinates. I believe these will work better:

            .mCSB_scrollTools .mCSB_buttonUp{ background-position:0 0; /* buttonUp locations are 0 0/-16px 0/-32px 0/-48px 0 (white) and -80px 0/-96px 0/-112px 0/-128px 0 (black) */ } .mCSB_scrollTools .mCSB_buttonDown{ bottom: 0px; background-position:0 -20px; /* buttonDown locations are 0 -20px/-16px -20px/-32px -20px/-48px -20px (white) and -80px -20px/-96px -20px/-112px -20px/-128px -20px (black) */ } .mCSB_scrollTools .mCSB_buttonLeft{ background-position:0 -40px; /* buttonLeft locations are 0 -40px/-20px -40px/-40px -40px/-60px -40px (white) and -80px -40px/-100px -40px/-120px -40px/-140px -40px (black) */ } .mCSB_scrollTools .mCSB_buttonRight{ background-position:0 -56px; /* buttonRight locations are 0,-56px/-20px -56px/-40px -56px/-60px -56px (white) and -80px -56px/-100px -56px/-120px -56px/-140px -56px (black) */

        • malihu
          Posted on September 5, 2012 at 01:16 Permalink

          Good idea. I’ll put the dark and light buttons css locations in the stylesheet for reference. Thanks!

          EDIT: Done.

          Reply
  22. Eric Buckley
    Posted on September 2, 2012 at 12:42 Permalink

    Hi, this plug-in is very well put together and complete. I’m very impressed. I am trying to use it on a project where we have “tabbed content” using jQuery.

    The code for the tabbed content looks like this:
    $(".mission-content").hide(); $("ul.mission-menu li:first").addClass("active").show(); $(".mission-content:first").show(); $("ul.mission-menu li").click(function(e) { e.preventDefault(); $("ul.mission-menu li").removeClass("active"); $(this).addClass("active"); $(".mission-content").hide(); var activeTab = $(this).find("a").attr("href"); $(activeTab).fadeIn("slow",function(){ $(".mission-text").mCustomScrollbar("update"); }); });

    The HTML markup looks like this:

    <ul class="mission-menu"> <li><a href="#tab_1">Tab1 Menu Title</a></li> <li><a href="#tab_2">Tab2 Menu Title</a></li> </ul> <div id="main-content"> <div id=tab_1" class="mission-content"> <h2>Some title</h2> <div class="mission-text"> Lorem ipsum................ </div> </div> <div id=tab_2" class="mission-content"> <h2>Some title</h2> <div class="mission-text"> Lorem ipsum................ </div> </div> </div>

    The tabs work fine and the scrollbar shows up fine on the first tab. But even with the “update” element in the tab jQuery ccode, it refuses to add in the scrollbars when the second tab is clicked.

    What am I missing here?

    E.

    Reply
    • malihu
      Posted on September 2, 2012 at 18:44 Permalink

      Hello,

      I assume you have applied custom scrollbars to all your .mission-text elements like this:
      $(".mission-text").mCustomScrollbar();
      Is this correct?

      Make sure .mission-text have a height value. Also, you can call the update method only on the active tab like this:
      $(activeTab).fadeIn("slow",function(){ $(this).find(".mission-text").mCustomScrollbar("update"); });

      An alternative way would be to apply a single custom scrollbar only on .main-content (which should have a height value specified and probably overflow:auto):
      $(".main-content").mCustomScrollbar();
      and update it:
      $(activeTab).fadeIn("slow",function(){ $(".main-content").mCustomScrollbar("update"); });
      This way, you use a single scrollbar instead of multiple ones for each tab.

      Reply
      • Eric Buckley
        Posted on September 4, 2012 at 14:41 Permalink

        Thank you Malihu. You are a star!

        Yes, I did have the command to apply the scrollbars already in the code.

        Just using your reformed jQuery code solved my problem. I knew I was missing something there.

        Recommendations and a donation is on it’s way. I really appreciate you’re work here.

        Cheers.

        Reply
  23. Yasen
    Posted on September 1, 2012 at 15:37 Permalink

    Hello. Im making one new website – http://radiorock-bg.com/test/darin/ . The design is not finished yet. I really liked your custom scrollbar and I want to use it but something is going wrong… I followed the steps here – http://manos.malihu.gr/jquery-custom-content-scroller but nothing happen. Please, can you help me a little bit…?

    Reply
    • malihu
      Posted on September 1, 2012 at 17:19 Permalink

      Hello,

      In your CSS, you must give .content a height value (pixels, percentage etc.) instead of just max-height.

      If you don’t want to define a specific height value and use only max-height, please see the following example and view its source to get the additional code:
      http://manos.malihu.gr/tuts/custom-scrollbar-plugin/maxheight_example.html

      Reply
      • Yasen
        Posted on September 1, 2012 at 18:06 Permalink

        Thanks man! It works 🙂

        Sorry, can you remove or edit my post, `cuz I posted my contact data there…

        Reply
        • malihu
          Posted on September 1, 2012 at 19:13 Permalink

          Of course. Removed.

          Reply
  24. e-zheg
    Posted on September 1, 2012 at 12:52 Permalink

    Hello, do your script support both vertical and horisontal scroll?
    i’ve got page >8000x>13000px and do not want to use standart scrollbars…

    Reply
    • malihu
      Posted on September 1, 2012 at 17:22 Permalink

      Nope, only one axis scrolling on a single element.

      Reply
  25. Atif Meer
    Posted on August 30, 2012 at 14:14 Permalink

    Like this plugin and also detailed explaination.
    Wish you best of luck.

    Reply
  26. Sebastien
    Posted on August 30, 2012 at 12:42 Permalink

    Hey !

    So I am trying to use this plugin, looks great, but I just can’t seem to get it working !
    I have a simple div with overflow:auto; a height and a width, and I just can’t seem too scroll…

    I was on jquery 1.8.0, but since the comment above said it wasn’t working with it I tried with 1.7.1 and still can’t get it working.

    Do you think you could have a look ? Here’s the web page: http://pbmaintenance.fr/produits.php

    It shows up but I just can’t scroll.

    Thanks in advance !

    Reply
  27. bloor
    Posted on August 30, 2012 at 11:28 Permalink

    Not working with jQuery 1.8 even though i receive no console errror at all ._.
    … it took me 2h to realise it was the jQuery’s fault :[

    Reply
    • malihu
      Posted on August 30, 2012 at 15:47 Permalink

      Hi,

      It does work with jQuery 1.8. Try to use jQuery 1.8 with the latest version of jQuery UI (1.8.22 or 1.8.23).

      EDIT: I’ve included jquery-1.8.0.min.js and jquery-ui-1.8.23.custom.min.js in the download archive.

      Reply
  28. William
    Posted on August 30, 2012 at 02:02 Permalink

    Lovely work! Thank you Sir.

    I’ve implemented your slider. It’s slotting in really easily, but I’m having an issue in Chrome, the images judder when sliding. FF & IE9 are working well.

    You can see the page here http://wgmphoto.com/21c. If you click on the red 21C I slide out a pane which has the slider.

    The images are a bit big and will be reduced in the final version, but I don’t believe that should cause what I’m seeing.

    Can you see the issue / a solution?

    Thanks again, W.

    Reply
    • malihu
      Posted on August 30, 2012 at 16:01 Permalink

      Hello,

      Images judder is due to browser’s engine performance.
      You could reduce the images and maybe remove box-shadow (CSS shadows have big impact on performance esp. in Chrome).
      You could also try setting scrollInertia option parameter to zero, which removes the scrolling easing:
      scrollInertia:0

      Reply
  29. Clément
    Posted on August 29, 2012 at 20:57 Permalink

    Fucking great man!

    Reply
  30. ink
    Posted on August 28, 2012 at 21:52 Permalink

    Thanks for great script!
    I found an issue.
    It appears in last Firefox and Opera, not Chrome.
    If I use @font-face (Century Gothic in .ttf format actually, I think others too) in scroll area and move scrollbar to the bottom position (or scroll with mouse wheel to the end) there is still some text that not displayed because it below visible area.
    But I found some kind of workaround. This would be simplier with ‘onInit’ or ‘onLoad’ callback.

    updated = false; $(".scroll").mCustomScrollbar({ callbacks:{ onScroll:function(){ if (!updated) { // run this only once $(".scroll").mCustomScrollbar("update"); // after this all text becomes visible when scrollbar at bottom position updated = true; } } } });

    Reply
    • malihu
      Posted on August 28, 2012 at 23:44 Permalink

      Hello,

      On the demos I use custom fonts without any issues so I can’t really say what could be wrong. Sounds like fonts are not fully loaded when plugin initiates. Do you call mCustomScrollbar on window load or document ready? To make sure fonts are loaded, you must call the plugin on window load.

      Reply

Comments pages: 1 17 18 19 20 21 85

Post a comment

Your e-mail is never published nor shared. Required fields are marked *

You may use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>
You can write or copy/paste code directly in your comment using the <code> tag:
<code>code here...</code>
You may also use the data-lang attribute to determine the code language like so:
<code data-lang-html>, <code data-lang-css>, <code data-lang-js> and <code data-lang-php>

css.php