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,625 Comments

Post a comment

Comments pages: 1 24 25 26 27 28 84

  1. Gasara
    Posted on December 16, 2012 at 07:02 Permalink

    Thank you very much! Superb work!

    Reply
  2. Neo
    Posted on December 15, 2012 at 16:30 Permalink

    Dude the jquery-ui plugin is too big to be used . Is there any way to get an alternative to that ? i’m using jquery-ui.min.js and it still is about 196KB . any solutions to that ?

    Reply
    • malihu
      Posted on December 16, 2012 at 04:28 Permalink

      I don’t have any jquery-ui file in the archive that’s more than 45kb. Do you use those? If you’re referring to Google’s CDN file, it’s most likely cached by the browser so size won’t matter.

      Reply
  3. StevenCM
    Posted on December 15, 2012 at 14:42 Permalink

    Hi all,

    This looks like a great plugin but it is not working for me. I get no scrollbars at all!
    I’m building a WordPress site based on Twitter Bootstrap.
    I tried to troubleshoot myself by deteting all other scripts/CSS in my WordPress theme but nothing brings up the scrollbars.

    I’ve noticed in Firebug that there’s a mCS_no_scrollbar class added and the the mCSB_scrollTools are set to display:none

    I dont understand what causes this issue

    <div class="wrapper"> <div id="content_1" class="content mCustomScrollbar _mCS_1"> <div id="mCSB_1" class="mCustomScrollBox" style="position:relative; height:100%; overflow:hidden; max-width:100%;"> <div class="mCSB_container mCS_no_scrollbar" style="position:relative; top:0;"> <!-- content comes here --> <div class="mCSB_scrollTools" style="position: absolute; display: none;"> <a class="mCSB_buttonUp" style="display:block; position:relative;"></a> <div class="mCSB_draggerContainer" style="position:relative;"> <div class="mCSB_dragger" style="position: absolute; top: 0px;"> <div class="mCSB_dragger_bar" style="position:relative;"></div> </div> <div class="mCSB_draggerRail"></div> </div> <a class="mCSB_buttonDown" style="display:block; position:relative;"></a> </div> </div> </div> </div>

    Thank you in advance!

    Reply
    • malihu
      Posted on December 15, 2012 at 15:01 Permalink

      Hello,
      Without knowing exactly what your page code is, it seems that the script assumes your content doesn’t need a scrollbar (content not long enough). Have you given a height value to your element? Also, do you load content dynamically?

      Reply
      • StevenCM
        Posted on December 15, 2012 at 15:18 Permalink

        Hi Malihu,

        Sorry I didn’t see your answer above. Thank you for replying!
        There should be enough content, the content is loaded in WordPress using get_posts().
        All CSS is copied from your fluid_scrollbar_example.

        Regards,
        Steven

        Reply
      • StevenCM
        Posted on December 15, 2012 at 15:44 Permalink

        Hi Malihu,

        I set back everything to default, and uploaded the site to my webserver.
        This is a complete copy of your fluid_scrollbar_example inside my WordPress theme.
        http://www.exposit.be/notelaer/

        As I said before; it seems like I cant set html,body{height:100%} in Twitter Bootstrap.

        Thanks for your help!

        Reply
        • malihu
          Posted on December 16, 2012 at 04:45 Permalink

          Your #content_1 div just expands to fit its content. No matter how I resize the browser, the content is always visible (that’s why there’s no need for scrollbars).

          Try to give #content_1 a fixed height value (instead of percentage) or give your #main div a height.
          As it is now, the #content_1 is 85% of .wrapper, which is 80% of your #main div which does not have any height values (it’s the entire document, 4292px).

          Reply
          • StevenCM
            Posted on December 18, 2012 at 00:43 Permalink

            Hi Malibu,

            Thank you for your efforts and support!
            I’ve set a fixed height to #content_1 but still no scrollbars for me…
            I am sorry but I can’t set a fixed height to the #main div.

            Kind regards!

    • StevenCM
      Posted on December 15, 2012 at 15:12 Permalink

      For your info: I’m trying to rebuild the fluid_scrollbar_example.
      It seems like I cant set html,body{height:100%} in Twitter Bootstrap.
      Is there another way to achieve this?

      Thanks!

      Reply
  4. Afonso Gomes
    Posted on December 15, 2012 at 13:24 Permalink

    WOW!

    Amazing amazing script. It’s so much more complete than any other Scoller plugins around, incluing all paid ones at Code Canyon. And you provide it for free…. Kudos to you sir. I’m definitelly going to donate some bucks as appreciation for this! Well, well done!! And, thanks, a lot!

    Small question tho, using it as an horizontal scroller in a div … is it possible to make the mouse wheel keep scrolling vertically after that div reaches the end of horizontal scrollable area? This detail is bugging me… would love to get it done for perfection sake but it’s no problem if it isn’t possible.

    Cheers and thanks again Malihu,
    Afonso Gomes

    PS: By the domain of your site … I notice we’re partners in this economic crisis 😀

    Reply
    • malihu
      Posted on December 15, 2012 at 14:25 Permalink

      Hi and thanks a lot for your comments 🙂

      I know what you mean by triggering the default browser scrolling when custom scrolling boundaries are reached. I’ve made a few tests (few versions ago) in this direction but I need to test it more to implement a more efficient solution in the plugin script. I’ll definitely check it thoroughly on the next update.

      By the domain of your site … I notice we’re partners in this economic crisis

      Indeed! lol

      Reply
      • Afonso Gomes
        Posted on December 23, 2012 at 15:48 Permalink

        Hey malihu …

        Another querstion!

        Is it possible to have this plugin running without jQuery.UI and having this instead http://css-tricks.com/snippets/jquery/draggable-without-jquery-ui/ to give support to the draggable feature?

        I’m asking cause I guess there must be lots of people like me that have to include the jquery.UI file just because of your plugin … and that’s an addition 60KB of page loading time…

        Will be waiting for your input. Merry Christmas if we don’t talk before tomorow 🙂

        Reply
        • malihu
          Posted on December 23, 2012 at 17:11 Permalink

          Not at the moment.

          I’m testing few things for the next version and I’ll probably integrate my own drag’n’drop function (instead of jQuery UI one). I’m also making some changes in the script for different easings and tweens to greatly increase performance.
          If everything goes well, the next version will not require the jQuery UI 😉

          The script of course will increase in file size but I’m trying to integrate most stuff inside the plugin file, in order to have fewer requests and decreased overall loading time.

          Reply
  5. Vladyn
    Posted on December 15, 2012 at 09:07 Permalink

    Awesome plug-in, but I’m really confused – at the moment I upload it on my server (I’m integrating it in Expression Engine 1.6.x by the way) Everything stops. There are no errors and any console log messages… and there is no scroll as well. Is it possible to be something with the server environment? …or platform?

    You can clearly see what I’m talking about the here

    Reply
    • malihu
      Posted on December 15, 2012 at 14:57 Permalink

      Hello,
      The plugin seems to be working in your page now. I’d suggest to download and implement the latest version (2.3.1).

      Reply
  6. Bren
    Posted on December 15, 2012 at 00:14 Permalink

    Dude, this is a great plugin and I am just loving it. It is easy to modify and adapt (more or less – I’m a little fresh at jQuery), it works perfect, and it looks great. I just spent a few hours trying to learn enough jQuery to modify your plugin to do something I need, but it turns out, you already built it in! So many options. Thanks and great work!

    Reply
  7. trinadh
    Posted on December 14, 2012 at 15:23 Permalink

    Hi folks,

    I am using the customScroll bar for one of my application.
    When i inspect the heap profile in the Chrome Developer tools, it is showing some memory-leaks (detached DOM nodes) and the DOM node when inspected is pointing to div “mCustomScrollBox”.

    I am using the scrollbar with the following options :
    ————————————————————–
    $(“#divId”).mCustomScrollbar({
    scrollButtons: {
    enable: true
    },
    advanced: {
    updateOnBrowserResize: true,
    updateOnContentResize: false,
    autoExpandHorizontalScroll: false
    }
    });
    ————————————————————–
    I am using the update method() whenever the changes are done to “divId”.

    Do we need to call destroy() method explicitly to detach the div’s added by this plugin ?

    Reply
    • malihu
      Posted on December 15, 2012 at 06:19 Permalink

      Use destroy method only when you want to completely remove the custom scrollbar and revert the element on its original state (before plugin initiated). When you change just the content of the scrollable container you normally call the update method.

      Reply
  8. Nate
    Posted on December 13, 2012 at 21:27 Permalink

    How could i check if function ontotalscrollback is true? I mean i do auto upload and i need to upload only when scroll is at the top.

    Reply
    • malihu
      Posted on December 13, 2012 at 23:24 Permalink

      onTotalScrollBack callback will trigger your function(s) only when scrolling to top (callbacks example: http://manos.malihu.gr/tuts/custom-scrollbar-plugin/callbacks_example.html). You should simply place your auto-upload function in onTotalScrollBack (no need to check if true as the script does it for you).

      Reply
      • nate
        Posted on December 15, 2012 at 18:07 Permalink

        Yea.. I put my setinterval into ontotalscrollback and it uploads everytime, even when scroll is not at the top…

        Reply
        • malihu
          Posted on December 16, 2012 at 04:49 Permalink

          Why do you need setInterval for? Without seeing your code, I can’t really help. Can you send a link?

          Reply
          • nate
            Posted on December 18, 2012 at 19:33 Permalink

            $(‘.chat-messages-scroll’).mCustomScrollbar({ scrollInertia:0, callbacks:{
            onTotalScrollBack:function(){
            setinterval(refreshcontent,10000);
            }}, advanced:{
            updateOnContentResize: true
            }});

        • malihu
          Posted on December 19, 2012 at 11:32 Permalink

          If you’re not clearing setInterval, it’ll run every 10000 milliseconds no matter what. You can simply call your refreshcontent function without the setInterval and it’ll trigger every time the user scrolls to top.

          Reply
          • nate
            Posted on December 19, 2012 at 16:13 Permalink

            You still didn’t get it… I need to keep refreshing content while scroll is on top! I mean i need to refresh it every 10secs if scroll is on top, if it’s scrolled down i need to stop refreshing…

        • malihu
          Posted on December 19, 2012 at 17:22 Permalink

          Ok. You still need to clear you interval when scroll is not at the top. You setInterval keeps uploading even when scroll is not at the top because you’re not clearing it (clearInterval()).

          In order to clear it, you need to give it an id (placing it inside a variable). You could then set it on onTotalScrollBack and clear it on onScroll & onTotalScroll.

          Your code could be something like:
          var myInterval; $('.chat-messages-scroll').mCustomScrollbar({ scrollInertia:0, callbacks:{ onTotalScrollBack:function(){ myInterval=setinterval(refreshcontent,10000); }, onScroll:function(){ clearInterval(myInterval); }, onTotalScroll:function(){ clearInterval(myInterval); } }, advanced:{ updateOnContentResize: true } });

          Hope this helps

          Reply
          • nate
            Posted on December 19, 2012 at 19:24 Permalink

            That’s what i was looking for! Thanks, you are amazing 🙂

          • nate
            Posted on December 22, 2012 at 01:07 Permalink

            damn it… if i scroll down and then up and down and then up again (till the top) it just sets me 3 or more intervals… and if i trigger clearinterval on onscrollstart it overload the system.. it seems there is no option.. 😕

          • nate
            Posted on December 22, 2012 at 01:13 Permalink

            found the solution lol 😀

            function conupdate() {
            if (actre == 0) { reloadcon(); }
            }

            var actre=0;
            $(‘.chat-messages-scroll’).mCustomScrollbar({ scrollInertia:0, callbacks:{
            onTotalScroll: function() {
            actre=0;
            },
            onScroll: function(){
            actre=1;
            }}, advanced:{
            updateOnContentResize: true
            }});

            setInterval(conupdate, 5000);

            i hope it will be helpful for someone..

  9. Don
    Posted on December 13, 2012 at 09:36 Permalink

    Hi folks,

    I have finally upgraded to the second version. It is simply marvelous. Here is some feedback for Malihu and others.

    It works on HTC EVO V with Android great. It also works in IE, Chrome, Firefox in multiple versions. I also had a buddy test it on his Iphone and it was working there too. The Iphone apparently does not have the easing animation when the Iphone is flipped horizontally in the landscape mode. It scrolls normally with the pace of your finger swipe, but stops when your finger stops moving. When you flip the Iphone in Portrait mode (like you would talk on the phone) the easing starts working somewhat but not super smooth. The directional buttons work on an Iphone as well by clicking them. I massaged the CSS to feature larger buttons for this purpose. It takes a lot of tricks to accomplish this with the CSS using Sprites, so I wouldn’t suggest this unless you know what you are doing. You may have to live with the smaller arrows that come with the default installation.

    In my gallery, I am using the scroller in a horizontal format so that it works on desktops and mobile devices in a similar fashion. I will use media queries to resize the resolution for phones and tablets and have a couple of versions tested and working.

    All of my content is fed dynamically by PHP on the fly sniffing all the images out of a folder with thumbs and large images. I created an array from the folder of images dynamically and I use shuffle() with PHP to shuffle the deck of cards when the user refreshes their browser. The large images open in a lightbox style window when you click on the thumbnails embedded in the scroller. I would like to report that the Javascript coded by Malihu works pixel perfect resizing the dynamically fed thumbnails which is something I struggled with in the first version. I have tested the 2nd version scroller with 120+ images with thumbnails sized 215px wide x 160px tall. So they are pretty large. I will probably throw another 100+ images into the folder and keep it around 250 images. This is a lot, but the script appears to handle it well. Great job Malihu! One other thing I did to speed up the scrolling with this many images was change the setting mouseWheel to an Integer value. I I set it to mouseWheel:90, and you can flick right through the images very quickly.

    VERY IMPORTANT TIP HERE!!!!
    If you decide to use an href tag to open larger images in a lightbox window, you need to adjust one of the advanced settings like this:

    autoScrollOnFocus:false /*auto-scroll on focused elements: boolean*/

    You need the value to be false, not true.
    The default value is true.

    However, if you leave it true, your href tag will not open the larger image until the second mouse click. On the first mouse click, it will scroll all the way to the end of the scroller as if you had clicked href=”#”. The reason for this is that the Javascript thinks the click is a “focus”. So you need to make the value false. After you do this, all of your href’s will open the larger image like you want them too.

    I hope to have this tested on a IPad soon, and I will report back the results once I get a buddy to look at it.

    Anyway, I hope this input is helpful to some folks that may be on the fence trying the scroller out with some more advanced settings. Dive in. It’s worth your time. It will work, but you will need to have some patience coding it if you are not adept at HTML, PHP and don’t understand how dynamically fed data is coded.

    Don

    Reply
    • malihu
      Posted on December 13, 2012 at 10:11 Permalink

      Hi Don,

      Thanks a ton for your comments 🙂 Especially for taking the time to post your findings and feedback on the scrollbar within such an advanced implementation as yours.

      Also great to hear how exactly works on iPhone (don’t have one). What I do have is an iPad (2), so whenever you like, send me link to check it for you.

      Thanks again for such informational post as it’ll surely help others (and me trying to help people).

      PS. I’ve just finished coding a script that replicates iOS/Android touch-swipe scrolling with momentum (made it for another gallery script). I’ll test it with the scrollbar and if everything goes well, I’ll implement it on the plugin.

      Reply
    • OnTheGo
      Posted on December 29, 2012 at 04:21 Permalink

      I tried it on iPad 2 and also got the easing prob. I realise that it happens when browser auto resize to fit the page. So if we use viewport scroll works fine.

      I´m still very noob, but it works for me. I hope it works for you.

      Reply
      • malihu
        Posted on December 29, 2012 at 12:27 Permalink

        This happens due to bug between a zoomed webkit browser and jQuery animate. If everything goes as planned, next version will not have this issue.

        Reply
  10. AoEmaster
    Posted on December 12, 2012 at 22:21 Permalink

    Hello !

    Best jQuery plugin ever *_* I totaly love it !

    It would be great if I could show the scroller only on mouseover event, and to put it over the content (with a position absolute).

    Reply
    • malihu
      Posted on December 13, 2012 at 03:05 Permalink

      Hello and thanks 🙂
      See my reply to comment #61 for showing & hiding the scrollbar on mouse-over.

      The scrollbar is positioned absolute (element .mCSB_scrollTools), so you can edit the CSS and position it wherever you like (see “Styling the scrollbars” for more info).

      Reply
  11. TJ
    Posted on December 12, 2012 at 00:49 Permalink

    Love the plugin, thanks for the work you put into it!

    I have one question regarding an issue with scrolling. If you have the ScrollButtons endabled, and you are scrolling the bar via the Dragger and “mouseUp” while over one of the buttons, the “mouseUp” event fires on the button, but does not appear to fire on the Dragger, and you are still able to scroll with the mouse until you click anywhere again.

    This is minor, but easy to reproduce as you are scrolling and over shoot either end of the scrollbar and let off the mouse over one of the buttons. I am no expert on JavaScript and have been unable to come up with a solution, what would you suggest?

    What I have attempted so far is firing a “mouseUp” on the Dragger when the “mouseUp” is fired on the button, but cannot seem to get a result.

    Reply
    • malihu
      Posted on December 12, 2012 at 01:15 Permalink

      Hello,
      Thanks a lot for your comments and feedback 🙂
      I see what you mean. Until I update the script, edit jquery.mCustomScrollbar.js and remove the following lines:
      528, 513, 492 and 477 (e.stopPropagation() code).

      Reply
  12. Adam Dougherty
    Posted on December 11, 2012 at 17:14 Permalink

    Hi mate,

    great plugin! Just one tiny problem, if I want a horizontal scrollbar on one div, and a vertical scrollbar on another, it adds horizontal to both… Not ideal!

    Can you please advise how I fix this?

    Thanks, Jam.

    Reply
    • malihu
      Posted on December 11, 2012 at 23:50 Permalink

      In the example below, only the .horizontal element will have a horizontal scrollbar.
      $(".vertical").mCustomScrollbar(); $(".horizontal").mCustomScrollbar({ advanced:{ horizontalScroll: true } });

      Reply
  13. 'Ley Missailidis
    Posted on December 11, 2012 at 16:27 Permalink

    Hi,

    I just started working on a project and there is an odd behaviour with it’s implementation of your plugin and I can’t quite figure out how to make it stop it.

    Essentially if you go here and click on one of the sub categories the default behaviour is to set to scroll to the bottom – ie top is set to the length of the div – but I don’t want it to do that and I can’t seem to figure out where the reset is to make it stop.

    Any help would be greatly appreciated.

    Thanks.

    Reply
    • malihu
      Posted on December 12, 2012 at 00:38 Permalink

      The first of your sections behaves normally (doesn’t scroll to bottom), so the issue has something to do with your js click events (inside scripts.js which I cannot edit).

      Since you’ve set updateOnContentResize to true (in your scrollbar_options variable), try removing the update methods inside your click events (or keep them and set it to false).

      Reply
      • 'Ley Missailidis
        Posted on December 12, 2012 at 16:54 Permalink

        Thanks. I just walked into this project and I never used your plugin before. Thanks for the insight.

        Reply
  14. Tony
    Posted on December 11, 2012 at 16:21 Permalink

    Hello,

    Could you add function similliar to top().position, which counts scroll position from the bottom? I mean by default my scroll is set to the bottom and user have to scroll it up. I want to do that when the user scrolls up the new content loads. I can do it easily if user scrolls from top to bottom, but not reverse. I hope you understood me 🙂

    P.S. GREAT plugin!

    Reply
    • malihu
      Posted on December 12, 2012 at 00:46 Permalink

      I already have 😉
      The latest version (2.3.1) has a new callback onTotalScrollBack which will fire your function(s) when the user scrolls to top or left (the opposite of onTotalScroll).
      Please see “Configuration” section for more info.
      I have a live example with all available callbacks here:
      http://manos.malihu.gr/tuts/custom-scrollbar-plugin/callbacks_example.html
      (see the message of onTotalScrollBack when you scroll to top).

      Reply
  15. andrey
    Posted on December 11, 2012 at 16:17 Permalink

    Hi!
    Seems like the plugin prevents mouse clicks on content sometimes. I have content that is scrolled horizontally:
    $(“.PreviewsContainer”).mCustomScrollbar(
    {
    horizontalScroll:true,
    advanced: {
    updateOnBrowserResize:true,
    updateOnContentResize:true,
    autoExpandHorizontalScroll:true
    }
    }
    );
    and click on preview ( element) doesn’t work each time. This happens when mouse hovers preview and user clicks on it. BUT not every time.
    Will be very grateful for Your reply.

    Reply
    • malihu
      Posted on December 12, 2012 at 00:54 Permalink

      I can’t really know what the problem could be. The plugin doesn’t modify your content at all (only wraps it in other elements). Have you tried removing the plugin and see if the problem remains? Is it a plain html link or a link handled by javascript?

      Reply
      • andrey
        Posted on December 12, 2012 at 01:31 Permalink

        Thanks for your reply. Yes, I checked my components behaviour without plugin and click events were handled right.
        In my case each element itself is an anchor with JS event handler (previews in photogallery).
        I also noticed that there are several places in your plugin with calls to preventDefault() and stopPropagation() for a mouse event, but they not seem to be related to mouse events from wrapped elements…

        Reply
      • andrey
        Posted on December 12, 2012 at 01:55 Permalink

        upd: managed to reproduce – click does not work if user presses mouse down then holds it in this state for some time (> 0.5 sec) and releases. So the event sequence is : MouseDown->hold_some_time->MouseUp. The same situation if the click is too fast. And I tried to do all this without plugin – everything works correctly.
        This issue is not critical for me, but maybe can help you to improve the plugin.
        My code, which may be useful for reproducing this bug (if it is):
        <div class="PreviewsContainer"> <div id="previews"> <div id="previewHover"> <ul> <li><a href="#photo1" onclick="handlePreviewClick('../assets/photos/gallery/1.jpg', this);"></a></li> <li><a href="#photo2" onclick="handlePreviewClick('../assets/photos/gallery/2.jpg', this);"></a></li> <li><a href="#photo3" onclick="handlePreviewClick('../assets/photos/gallery/3.jpg', this);"></a></li> <li><a href="#photo4" onclick="handlePreviewClick('../assets/photos/gallery/4.jpg', this);"></a></li> <li><a href="#photo5" onclick="handlePreviewClick('../assets/photos/gallery/5.jpg', this);"></a></li> <li><a href="#photo6" onclick="handlePreviewClick('../assets/photos/gallery/6.jpg', this);"></a></li> <li><a href="#photo7" onclick="handlePreviewClick('../assets/photos/gallery/7.jpg', this);"></a></li> <li><a href="#photo8" onclick="handlePreviewClick('../assets/photos/gallery/8.jpg', this);"></a></li> <li><a href="#photo9" onclick="handlePreviewClick('../assets/photos/gallery/9.jpg', this);"></a></li> <li><a href="#photo10" onclick="handlePreviewClick('../assets/photos/gallery/10.jpg', this);"></a></li> <li><a href="#photo11" onclick="handlePreviewClick('../assets/photos/gallery/11.jpg', this);"></a></li> </ul> </div> </div> </div>

        code with plugin usage on my component was posted above.

        Reply
        • malihu
          Posted on December 12, 2012 at 06:24 Permalink

          Hello,
          I made a test with links containing onclick attributes that fire a simple js function (alerts a simple message) and I didn’t had any problem (fast, slow, all clicks worked).

          I don’t know the code of your handlePreviewClick function but maybe try adding “return false” to your events and see if this fixes the issue.

          Reply
          • andrey
            Posted on December 12, 2012 at 11:53 Permalink

            ok, thank You! It really could be the problem on my side, so I’ll check everything again.
            Very liked Your plugin – a nice, professional thing, good work)

  16. marek1
    Posted on December 11, 2012 at 11:26 Permalink

    I have ~1000 loaded dynamicaly elements inside scroller and mouse wheel scroll doest work. When I limit items to 10, mouse wheel trigers scrolling. How to fix it?

    Reply
    • malihu
      Posted on December 11, 2012 at 13:11 Permalink

      I can’t really tell… Do you get any console errors? Can you send a link in order to check the code?

      Reply
      • marek1
        Posted on December 11, 2012 at 16:24 Permalink

        Ok I found solution, I had to set settings:

        scrollInertia:100,
        scrollEasing:”easeOutCirc”,
        mouseWheel:”pixels”,
        mouseWheelPixels:200,
        scrollButtons: {
        enable: true,
        scrollType:”continuous”,
        scrollSpeed:200,
        scrollAmount:200
        }

        without that, values to scroll are 0 or nearly 0 so events fire up but scroll is unnoticeable.

        Reply
  17. Vicati
    Posted on December 11, 2012 at 10:53 Permalink

    Hey there!

    i’m using your scrollbar and it fits great but i have a strange bug. My content is not displayed at the beginning and is loaded shortly after and the scrollbar doesn’t appear at first. Only after i pressed F12 for Firebug or resized the page trough scaling, the scrollbar appears. Can someone explain this to me?
    $(document).ready(function() { $("#first").animate({left: "280px"}, 500); $("#second").delay(200).animate({left: "415px"}, 600); $("#third").delay(400).animate({left: "550px"}, 700); $("#fourth").delay(600).animate({left: "685px"}, 800); $("#fifth").delay(800).animate({left: "820px"}, 900); $(".balken").delay(1600).animate({left:"298px"}, 200); $("#content_first").delay(1600).fadeIn(200); $("#secondnavi").delay(1600).fadeIn(200); }); $("#first").click(function() { $(".balken").animate({left:"298px", backgroundColor:"#0D439B"}, 200); $(".content").fadeOut(200); $("#content_first").delay(200).fadeIn(200); }); $("#second").click(function() { $(".balken").animate({left:"433px", backgroundColor:"#EE8E10"}, 200); $(".content").fadeOut(200); $("#content_second").delay(200).fadeIn(200); }); $("#third").click(function() { $(".balken").animate({left:"568px", backgroundColor:"#B53C7D"}, 200); $(".content").fadeOut(200); $("#content_third").delay(200).fadeIn(200); }); $("#fourth").click(function() { $(".balken").animate({left:"703px", backgroundColor:"#CF0F1D"}, 200); $(".content").fadeOut(200); $("#content_fourth").delay(200).fadeIn(200); }); $("#fifth").click(function() { $(".balken").animate({left:"838px", backgroundColor:"#0D00A3"}, 200); $(".content").fadeOut(200); $("#content_fifth").delay(200).fadeIn(200); }); //hover setTimeout(function(){ $("#first").mouseenter(function(){ $("#first").stop().animate({top: "52px"}, 150).mouseleave(function(){ $("#first").stop().animate({top: "60px"}, 150) }); }); $("#second").mouseenter(function(){ $("#second").stop().animate({top: "52px"}, 150).mouseleave(function(){ $("#second").stop().animate({top: "60px"}, 150) }); }); $("#third").mouseenter(function(){ $("#third").stop().animate({top: "52px"}, 150).mouseleave(function(){ $("#third").stop().animate({top: "60px"}, 150) }); }); $("#fourth").mouseenter(function(){ $("#fourth").stop().animate({top: "52px"}, 150).mouseleave(function(){ $("#fourth").stop().animate({top: "60px"}, 150) }); }); $("#fifth").mouseenter(function(){ $("#fifth").stop().animate({top: "52px"}, 150).mouseleave(function(){ $("#fifth").stop().animate({top: "60px"}, 150) }); }); },1800); (function($){ $(window).load(function(){ $(".content").mCustomScrollbar(); }); })(jQuery);

    Reply
    • Vicati
      Posted on December 11, 2012 at 12:45 Permalink

      I forgot to add my HTML-code, my bad.

      <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html"; charset="utf-8"> <meta name="Description" content="Christian Schwab Workbook"> <meta name="Keywords" content="Workbook, Mediamatiker"> <meta name="author" content="Christian Schwab"> <meta name="ROBOTS" content="index,follow"> <title>Multimedia</title> <link rel="stylesheet" type="text/css" href="style.css"> <link rel="stylesheet" type="text/css" href="jquery.mCustomScrollbar.css"> <script src="jquery/jquery.js"></script> <script src="jquery/jquery-ui-1.8.21.custom.min.js"></script> <script src="jquery/jquery.mousewheel.min.js"></script> <script src="jquery/jquery.mCustomScrollbar.js"></script> <script src="jquery/jquery_color.js"></script> </head> <body> <div class="wrapper"> <div class="container"> <div id= "secondnavi"> <div class="dot" id="button1"><img src="images/dot.png"></img></div> <div class="dot" id="button2"><img src="images/dot.png"></img></div> <div class="dot" id="button3"><img src="images/dot.png"></img></div> <div class="dot" id="button4"><img src="images/dot.png"></img></div> <div class="dot" id="button5"><img src="images/dot.png"></img></div> </div> <div class="content" id="content_first">Photoshop inhalte</div> <div class="content" id="content_second">Illustrator inhalte</div> <div class="content" id="content_third">Indesign inhalte</div> <div class="content" id="content_fourth">Flash Inhalte</div> <div class="content" id="content_fifth">Cinema4D Inhalte</div> </div> <div class="navi" id="first"><img src="images/png/ps.png"></img></div> <div class="navi" id="second"><img src="images/png/ai.png"></img></div> <div class="navi" id="third"><img src="images/png/id.png"></img></div> <div class="navi" id="fourth"><img src="images/png/fl.png"></img></div> <div class="navi" id="fifth"><img src="images/png/c4d.png"></img></div> <div class="balken"></div> <div id="wb"></div> <div id="multimedia_bottom_button"><a href="index.html"/></div> <div id="back"></div> </div> <script src="jquery/dynamic.js"></script> </body> </html>

      Reply
      • malihu
        Posted on December 11, 2012 at 13:10 Permalink

        Hello,
        Please check sections “Hiding & showing content blocks with custom scrollbars” and “Plugin methods: update” for info on why your scrollbars work only after a browser resize. For a quick “fix”, try setting the updateOnContentResize option parameter to true:
        $(".content").mCustomScrollbar({ advanced:{ updateOnContentResize: true } });

        Reply
        • Vicati
          Posted on December 11, 2012 at 13:48 Permalink

          Thanks a lot, works perfectly now!

          Reply
  18. Laur
    Posted on December 9, 2012 at 14:35 Permalink

    why does it have problems with dynamic content ? I have a container div in which I hide-show content and when I load the page the container doesn’t need scrolling so it is hidden but when I slide down the inner divs and it should show the scrollbar , it doesn’t

    Reply
    • Laur
      Posted on December 9, 2012 at 14:54 Permalink

      Nevermind, too blind to see the comment above with the “updateOnContentResize”

      Reply
  19. alessandra
    Posted on December 9, 2012 at 02:01 Permalink

    great!!

    Reply
  20. erkan
    Posted on December 9, 2012 at 01:42 Permalink

    hi. i would like to ask something about the “ui.js” . how will i download for corsum the ui.js from their website. what are the options required?

    Reply
    • malihu
      Posted on December 9, 2012 at 06:05 Permalink

      The archive contains a .txt (jquery/Download Builder for jQuery UI.txt) which states the components. Online here.

      Reply
  21. Darrell
    Posted on December 7, 2012 at 17:53 Permalink

    Is there a way to hide the scrollbar when not in use? Like the OS X mountain lion. It will only appear when you are scrolling the content, and hides it when there is no scrolling activity.

    Reply
    • Darrell
      Posted on December 7, 2012 at 18:50 Permalink

      Like fade it out when not in use and fade in when there’s scrolling.

      Reply
    • malihu
      Posted on December 7, 2012 at 19:09 Permalink

      You could either use the callbacks to add your own show/hide scrollbar functions, or you could do something like this:
      $(".content").bind("mouseenter",function(){ $(this).find(".mCSB_scrollTools").stop().fadeTo("fast",0.75); }); $(".content").bind("mouseleave",function(){ $(this).find(".mCSB_scrollTools").stop().fadeTo("fast",0); });

      Reply
      • Darrell
        Posted on December 7, 2012 at 19:45 Permalink

        Wow, this is great! Thanks!

        One more question, can I integrate mCustomScrollbar with fancybox? Or I really have to do it with this method:

        <a class="fancybox" href="content_1" rel="show-content">show/hide</a> $("#content_1").mCustomScrollbar(); //demo fn $("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"); }); });

        The problem is, it shows 2 of the content_1, first is up front that uses the fancybox and the second is behind that uses the rel=”show-content” method.

        Reply
        • malihu
          Posted on December 9, 2012 at 19:38 Permalink

          Try to attach the scrollbar to the fancybox element and set updateOnContentResize option parameter to true (see Configuration).

          Reply
  22. Genaro
    Posted on December 7, 2012 at 06:18 Permalink

    I had a drawback with the jquery.mCustomScrollbar plungins and dynamic content..

    updateOnContentResize doesnt work for me because i have dynamic content and no dynamic content. well i did that

    i will create another file jquery.mCustomScrollbar2.js, namely 2 plugins xD. thank you for jquery.mCustomScrollbar plungis.

    Reply
    • malihu
      Posted on December 7, 2012 at 18:37 Permalink

      You can call mCustomScrollbar function separately on multiple elements with a different set of options for each one. For example:
      $(".dynamic").mCustomScrollbar({ advanced:{ updateOnContentResize: true } }); $(".static").mCustomScrollbar({ advanced:{ updateOnContentResize: false } });

      Reply
      • Genaro
        Posted on December 10, 2012 at 21:25 Permalink

        thank you very much, also works great!. (y)

        Reply
  23. 박찬영
    Posted on December 6, 2012 at 03:49 Permalink

    Thanks :)..
    was solved that ploblem.
    Thank you to kind answers and very nice plugins.
    careful the cold..:)

    Reply
  24. Elliot
    Posted on December 6, 2012 at 01:02 Permalink

    Have you had any luck implementing this with touch-scrolling? It seems to work with touching the dragger to scroll, but not a traditional swipe (as in swiping with one finger within the div to scroll).

    Thanks!
    Elliot

    Reply
    • Elliot
      Posted on December 6, 2012 at 01:07 Permalink

      Haha, never mind! I just noticed you updated the plug-in a few days ago with this!!!

      Thanks!!!!!

      Reply
  25. Frazer
    Posted on December 5, 2012 at 23:40 Permalink

    I really like the scrollbar plugin – but I am unable to get it working in conjunction with JQueryUI tabs. I have something like this in the mark up:

    <div id="container"> <ul> <li><a href="#tab-1">Home</a></li> <li><a href="#tab-2">Home</a></li> </ul> <div id="tab-1" class="tabPage"> <div id="Div1" class="chartContainer"></div> <div id="Div2" class="chartContainer"></div> <div id="Div3" class="chartContainer"></div> <div id="Div4" class="chartContainer"></div> <div id="Div5" class="chartContainer"></div> <div id="Div6" class="chartContainer"></div> <div id="Div7" class="chartContainer"></div> <div id="Div8" class="chartContainer"></div> </div> <div id="tab-2" class="tabPage"> <div id="Div21" class="chartContainer"></div> <div id="Div22" class="chartContainer"></div> <div id="Div23" class="chartContainer"></div> </div> </div>

    and in script…

    $(document).ready(function () { var tabs = $("#container").tabs(); $(".tabPage").mCustomScrollbar({ mouseWheel: true, scrollButtons: { enable: true } }); }); Tabs work - scrollbar does not. Any suggestions greatly appreciated.

    Reply
    • malihu
      Posted on December 6, 2012 at 03:03 Permalink

      Try:
      $(".tabPage").mCustomScrollbar({ mouseWheel: true, scrollButtons: { enable: true, updateOnContentResize: true } });

      for more info see “Loading & updating content dynamically” and “Hiding & showing content blocks with custom scrollbars”.

      Reply
      • Frazer
        Posted on December 12, 2012 at 22:28 Permalink

        Thanks! That worked – however I still have a remaining problem. I apply the scrollbars to container divs on each of the tabs. When the page is rendered, the scrollbar appears just fine on the tab which is first active, however, when I change tabs, the scroll bar is initially not visible on the newly selected tab. If I resize the browser window, then the scrollbar appears. Is there some way to force the scrollbar to appear, say in a tab select event handler?

        Reply
        • malihu
          Posted on December 13, 2012 at 03:14 Permalink

          It should be visible. I’d need to see your page/code online to help, so send me a link if you can.

          Reply
  26. Alexander
    Posted on December 5, 2012 at 20:17 Permalink

    Thanks a lot for you work. Your plugin is really helpful.

    Question:
    How can I add two scrolls (horizontal and vertical) to my content?

    Reply
  27. Elliot
    Posted on December 4, 2012 at 18:55 Permalink

    Hi, great plugin, thanks!

    One small question: is there a way to have scrollInertia for the scrollbar, but to turn it off for the mousewheel?

    With apple’s built in inertia scrolling, there is a lag when scrolling with the mousewheel, but I like the inertia effect when using the dragger/scrollbar. Turning off inertia altogether makes the lag when using the mousewheel go away, but then of course you lose the effect when using the dragger.

    Thanks!

    Reply
    • malihu
      Posted on December 5, 2012 at 16:49 Permalink

      Not really. Scrolling inertia applies on all events. I’ll probably have to add an extra condition in the script that disables inertia for safari browser on OSX. I’ll check it further.
      Just a quick question: Does Apple’s built-in scrolling inertia applies only on Safari or on all browsers?

      Reply
      • Elliot
        Posted on December 5, 2012 at 20:40 Permalink

        Thanks for the quick reply!

        Appears to affect all browsers — the lag it creates is much more noticeable on horizontal scrolling divs than vertical, not sure why that would be….

        Cheers

        Reply
  28. 전정환
    Posted on December 4, 2012 at 18:15 Permalink

    In a commercial project will be used after modify.
    Available?
    GPL License?

    Reply
    • korean
      Posted on December 5, 2012 at 03:01 Permalink

      상업적으로 사용해도 무방할 것으로 생각됩니다.
      플러그인 js파일 내에 있는 라이선스만 수정하지 않는다면 별 문제 없어 보이는군요..
      Javascript 플러그인이 상업적 프로젝트에 이용하는데 있어, 유료로 제공되는 것은
      접하지 못한 것 같네요..
      유료라고 하는 jQuery 플러그인들은 PHP등의 서버사이드 언어와 함께 연동되어
      제공되는 경우입니다..
      제 견해이지만. 상업적으로 이용 하셔도 무방할 것 같습니다.
      Javascript는 어떤이의 주체가 없는 자유로운 Open소스이기 때문에
      이를 유료로 제공한다면 근본적 취지에 어긋나는 듯 합니다.
      js파일에 라이선스를 남겨주는 것은 개발자에 대한 성의라고 생각합니다…^^

      Reply
  29. 박찬영
    Posted on December 4, 2012 at 02:39 Permalink

    Made the movie you wanted…^^
    and uploaded on my server…
    Movie URL is

    http://www.flyfan.kr/jqueryError.avi

    If You can not understand,
    Request again, please..^^
    Tank you.!!

    Reply
    • malihu
      Posted on December 4, 2012 at 03:47 Permalink

      Thanks for making the video.
      Does the scrollbar still functions correctly after the debug error?
      What version of Internet Explorer are you using?

      Reply
      • 박찬영
        Posted on December 4, 2012 at 08:19 Permalink

        Complete debugging, but there is still a problem.
        the jQuery code is

        / / Click Button1
        $ (document). on (“click”, Button1, function () {
        $ (content DIV). load (page1.html, function () {$ (scroll DIV). mCustomScrollbar ();});
        }
        / / Click Button2
        $ (document). on (“click”, Button2, function () {
        $ (content DIV). load (page2.html, function () {$ (scroll DIV). mCustomScrollbar ();});
        }

        But,
        “$ (scroll DIV). mCustomScrollbar (” update “);” to “$ (contant DIV). load ….” before the start of a code to insert,
        The error does not appear.

        Internet browser I’ve tested IE7 ~ IE9,
        All, there was an error….:(

        Reply
        • malihu
          Posted on December 5, 2012 at 17:08 Permalink

          You’re getting the error cause you apply-remove scrollbar markup each time you click the buttons. Instead, you should just call the update method.

          The problem is that you’re loading your content inside a div without a class-name or id, removing the divs of the custom scrollbar in the process. What you should do, is apply the scrollbar normally (e.g. on window load) and call the update method inside your click events:
          $ (scroll DIV). mCustomScrollbar ("update");

          Reply
  30. Jochen Stärk
    Posted on December 3, 2012 at 15:10 Permalink

    When a mobile browser like FF portable is detected, the scrollbar vanishes. Is there a way to indicate to the user that there is a possibility to scroll (which is still possible – with a wipe gesture) like an arrow which vanishes when the scroll functionality is used for the first time?

    Reply
    • malihu
      Posted on December 3, 2012 at 15:16 Permalink

      Hello,
      Do you use the latest version (2.3)?

      Reply
      • Jochen Stärk
        Posted on December 6, 2012 at 17:16 Permalink

        Now I do, thanks, it’s solved.

        Besides, I use a patched version, I commented out the ll. 344-349 paragraph “check for safari browser on mac osx to lower mousewheel velocity” because the customer had complained that the wipe is much too slow on her mac with safari. I don’t remember if she has a touch screen or a multitouch capable input device. Maybe this was an issue in previous versions of safari only?

        Reply
        • malihu
          Posted on December 7, 2012 at 02:08 Permalink

          Maybe. I can’t really say as I don’t own a mac (with Apple’s built-in scrolling inertia) and cannot do proper testings.

          Reply

Comments pages: 1 24 25 26 27 28 84

Post a comment

Cancel reply

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