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 50 51 52 53 54 85

  1. OPcode
    Posted on August 30, 2014 at 04:01 Permalink

    Hello.
    While using onTotalScroll and onTotalScrollBack callbacks to update content of vertical news list I’ve noticed the following behaviour:
    1. When the dragger hits the bottom the content is added at the bottom, the container stays in place and the dragger adjusts its height and position – moves up relative to its previous position – so it can be moved to bottom again to trigger onTotalScroll. So all is good.
    2. When the dragger hits the top the content is added at the top, the container stays in place but visually due to added content it appears as though the container is moved down, the dragger adjusts its height and stays in place – at the topmost position – so it can’t be moved to the top again, you need first to move it down.

    To make it look like the container stays in place after adding content at the top I’ve tried scrolling to the element that prior to updating the content was first in the list but this is very noticeable.

    So my question is: is it somehow possible to make it look like the container always stays in place when adding content at the top?
    E.g. it could be some function that could freeze the container’s position with the option to signify that the content is being added at the top or at the bottom so that the css of the container could be adjusted accordingly.

    Reply
    • malihu
      Posted on August 30, 2014 at 04:49 Permalink

      Yes (with a bit of extra code).
      Your idea of using the scrollTo method is the correct way to do it. You need to set scrollInertia option parameter of the method to 0, so it scrolls “instantly” and also to find the proper position to scroll-to.

      The best way to find where to scroll-to is to subtract the “old” content height from the “new” one (you should be able to store the “old” content height in a variable before the new content is loaded). Then, you can use the result and subtract it from the current content position.

      It sounds a bit complicated but it’s not… for example:
      var oldContentHeight=$(".content .mCSB_container").innerHeight(); /* your code that loads new content... */ var heightDiff=$(".content .mCSB_container").innerHeight()-oldContentHeight; $(".content").mCustomScrollbar("scrollTo","-="+heightDiff,{scrollInertia:0});

      I’ve made a simple but fully working example where you can see and grab the code here:
      http://manos.malihu.gr/repository/custom-scrollbar/tests/infinite_scroll_reversed_demo.html

      Reply
      • OPcode
        Posted on August 30, 2014 at 10:09 Permalink

        Thank you for the answer.
        But unfortunately even scrollInertia 0 does not make the jitter go away. In your example this jitter is seen during the first content addition. It is not seen during the following additions because the content is the same.

        Reply
        • malihu
          Posted on August 30, 2014 at 16:58 Permalink

          Ah I see…
          This happens due to the 60 millisecond timeout of the method. If you need a quick fix (until I update the script), you can edit jquery.mCustomScrollbar.js, find line 619 and change 60 to 0.
          I’ll probably introduce an option parameter for this on the next update (in a few days).

          Reply
          • OPcode
            Posted on August 30, 2014 at 23:36 Permalink

            Unfortunately changing this timeout value to 0 or making the code from that setTimeout on lines 61* synchronous does not resolve the problem – the content’s jitter is still noticeable (in Firefox).
            Also I’ve noticed another kind of jitter – the dragger’s jitter. Sometimes when the dragger is large it is noticeable how after adding content at the top it first jumps to its new position and then adjusts its height (when updateOnContentResize is true) or vice versa (when updateOnContentResize is false and I first update scrollbar and then scroll). Or maybe I’m already seeing things after looking at the scrolling content too much.

        • malihu
          Posted on September 6, 2014 at 09:42 Permalink

          Sorry for the late reply!

          The jitter in Firefox is fixed in version 3.0.4 (just released). So check the demo one more time and download/use version 3.0.4.

          The scroll-to timeout can now be set via the timeout option of the method like this:
          $(selector).mCustomScrollbar("scrollTo",to,{scrollInertia:0,timeout:0});

          The second jitter you noticed should also be eliminated with new version, especially when using updateOnContentResize:false with the update method.

          Reply
  2. Anton
    Posted on August 29, 2014 at 14:04 Permalink

    Hello Malihu,

    i have an “Highslide Thumbnail Viewer” and i try to call an iFrame to give it new Scrollbars.
    The DIV i will call is: .highslide-body iframe.

    I give the iframe a new height…

    It not works…

    I need a help!

    Thanks

    Reply
  3. imran
    Posted on August 28, 2014 at 21:48 Permalink

    Hello sir, i have a problem with the js file. by using this stylish scrollbar i can’t use .toggle() function anymore. why it is conflicting with the jquery 1.7.2 ?
    and second please tell me how to make the scrollbar speed fast.

    Reply
    • malihu
      Posted on August 28, 2014 at 22:58 Permalink

      Hello,

      To change the scrolling momentum, use the scrollInertia option parameter. To change mouse-wheel “speed” use the mouseWheel:{ scrollAmount: integer } option parameter. For example:
      $(selector).mCustomScrollbar({ scrollInertia: 950, mouseWheel:{ scrollAmount: 100 } });

      For the first part of your question, I need more info about the problem or maybe a link to check it online.

      Reply
  4. Alva
    Posted on August 28, 2014 at 03:25 Permalink

    your plugin is awesome i integrate it in one of my websites.
    I would like to integrate it in a wordpress site, which would be the best approch to do this?

    Greetings

    Reply
    • malihu
      Posted on August 28, 2014 at 22:40 Permalink

      Hi,

      The following is a good way of adding the plugin in your theme manually:

      1. Create a new folder inside your theme directory and name it “custom-scrollbar”. Place the jquery.mCustomScrollbar.concat.min.js, jquery.mCustomScrollbar.css and mCSB_buttons.png files inside it.

      2. Create a new js file: jquery.mCustomScrollbar.init.js inside “custom-scrollbar” folder. Insert the following code in it, replacing selector with your element(s) and options:

      (function($){ $(window).load(function(){ $(selector).mCustomScrollbar({ theme:"dark" }); }); })(jQuery);

      3. Edit your themes functions.php and insert the following PHP code which loads plugin’s css and js files in your templates:

      function custom_scrollbar_init() { if(!is_admin()){ /* add plugin stylesheet */ wp_enqueue_style( 'customscrollbar-css', get_template_directory_uri() . '/custom-scrollbar/jquery.mCustomScrollbar.css' ); /* add plugin main js */ wp_enqueue_script( 'customscrollbar-js', get_template_directory_uri() . '/custom-scrollbar/jquery.mCustomScrollbar.concat.min.js', array('jquery'), '3.0.3', true ); /* add plugin init js */ wp_enqueue_script( 'customscrollbar-init-js', get_template_directory_uri() . '/custom-scrollbar/jquery.mCustomScrollbar.init.js', array('jquery', 'customscrollbar-js'), '3.0.3', true ); } } add_action('wp_enqueue_scripts', 'custom_scrollbar_init');

      4. Create your content and elements that’ll have a custom scrollbar and you’re done.

      You could of course skip the creation of jquery.mCustomScrollbar.init.js and either place its code directly in your theme’s footer.php or main js file or just add the mCustomScrollbar class to your element(s) to apply the scrollbar with the default options.

      Reply
      • Alva
        Posted on September 1, 2014 at 15:29 Permalink

        it Works like a charm thank you very much
        🙂

        Reply
  5. t0s
    Posted on August 27, 2014 at 14:57 Permalink

    Hi!

    Thank you for your plugin, but i have two questions:

    1) Is it normal behavior?
    // callbacks works fine
    $('#content').mCustomScrollbar({callbacks: { onScroll: function() { console.log('scroll') } }})
    // callbacks don’t works
    $('#content').mCustomScrollbar(); $('#content').mCustomScrollbar({callbacks: { onScroll: function() { console.log('scroll') } }})

    2) I write $(‘#content’).mCustomScrollbar(); but #content is empty and scroll does not appear. Then i add content in $(‘#content.mCSB_container’) and in some moment scroll appears. Can i listen this event?

    Reply
    • malihu
      Posted on August 28, 2014 at 01:36 Permalink

      1) Yes, this is normal behavior. To re-initialize a scrollbar with different options, most of the times you’ll need to destroy the scrollbar before calling mCustomScrollbar function again on the same element. For instance:
      $('#content').mCustomScrollbar(); $('#content').mCustomScrollbar("destroy"); $('#content').mCustomScrollbar({callbacks: { onScroll: function() { console.log('scroll') } }})

      2) There’s no user available callback within the plugin script to check if the scrollbar is visible/active or not. This said, you could get your element’s state as when no scrollbar is needed, it gets the class: mCS_no_scrollbar. This class won’t be present when content is long enough to require the scrollbar.

      Reply
      • t0s
        Posted on August 30, 2014 at 19:40 Permalink

        Ok, thank you very much!

        Sorry, I’m posted my questons twice

        Reply
  6. Tahir
    Posted on August 27, 2014 at 13:32 Permalink

    Is there a way to use a theme without javascript?

    Reply
    • malihu
      Posted on August 28, 2014 at 01:26 Permalink

      Yes, by using the data-mcs-theme attribute in your html. For example:
      <div data-mcs-theme="inset">...</div>

      Reply
      • Tahir
        Posted on August 28, 2014 at 12:45 Permalink

        Thanks. Now there’s another problem.

        I have a main container and a nested container with only horizontal scrollbar.
        <div class="pmain mCustomScrollbar" data-mcs-theme="dark"> <div class="pvert" data-mcs-axis="x" data-mcs-theme="dark">

        Problem is that the horizontal scrollbar (for nested container) only shows if I add the following code (taken from a demo).
        $(".pvert").mCustomScrollbar({ advanced:{autoExpandHorizontalScroll:true}});

        Reply
        • malihu
          Posted on August 28, 2014 at 20:00 Permalink

          The horizontal custom scrollbar works the same way CSS overflow-x:auto works, meaning your (inner) content should be wider than its container (the element with the scrollbar).

          For instance, when you have left-floated elements directly inside a div, those will stack horizontally only until they’ve reached the div’s right side. The next floated element(s) will form a “new line”.
          To make your content wider, you’d need to wrap your floated elements in another div which must have a higher width value than its container. For example:
          <div class="the-div-with-the-scrollbar" style="width:400px;"> <div class="the-wrapper-div" style="width:800px;"> <div class="floated-div">...</div> <div class="floated-div">...</div> <div class="floated-div">...</div> </div> </div>

          The plugin, via the autoExpandHorizontalScroll option parameter provides a way to add the wrapper (in the example above: .the-wrapper-div) automatically, in order to expand its width according to its contents without the need for you to add a fixed width.

          So you either need to use this option, or add such a div manually in your html.

          Hope this helps

          Reply
  7. Tomek
    Posted on August 27, 2014 at 11:53 Permalink

    Hi,
    When I refresh page first I see “standard” browser grey scrollbar (it means – about half second) and after that I see jquery scroll bar.
    Where is the reason?

    Reply
    • malihu
      Posted on August 28, 2014 at 01:21 Permalink

      This happens because the plugin is initialized when page is fully loaded, e.g.:
      $(window).load(function(){ $(".content").mCustomScrollbar(); });

      So while the page is loading, the default browser scrollbar appears normally and when all content is loaded, it’s replaced by the custom scrollbar. This happens on overflow:auto elements.

      There are 2 ways of dealing with this:
      1. Initialize the plugin on DOM ready:
      $(document).ready(function(){ $(".content").mCustomScrollbar(); });

      2. Set your element’s CSS overflow property to hidden:
      .content{ overflow:hidden; }

      Reply
      • Tomek
        Posted on August 28, 2014 at 13:03 Permalink

        Second option works. Thanks!

        Reply
  8. Fikri
    Posted on August 26, 2014 at 04:05 Permalink

    Hi..

    How to set scroll position to bottom when content update dynamically ?

    Thanks.

    Reply
    • ddd
      Posted on August 26, 2014 at 08:54 Permalink

      not any option… that time only default scroll will work not any jquery…

      like on popup.

      Reply
    • ddd
      Posted on August 26, 2014 at 08:59 Permalink

      or you can put that updated div in left or right position -9999% something .

      not put that updated div as display:none.

      Reply
    • malihu
      Posted on August 26, 2014 at 22:51 Permalink

      Each time the content is updated, call plaugin’s scrollTo method, e.g.: $(selector).mCustomScrollbar("scrollTo","bottom");

      Reply
  9. VamosErik88
    Posted on August 24, 2014 at 19:00 Permalink

    Hi malihu, I just started using your plugin on my startup website and I’m loving it!
    However I’m encountering a little issue. Let me explain:

    1. As stated on the instructions I’m initializing the plugin calling it in the header of my page and assigning the required tag to the body as follows:
    <body class="full-page mCustomScrollbar _mCS_3 mCS-autoHide" style="position: relative; overflow: visible;">

    2. The scrollbar works flawlessly. Now what I need is the body to scroll to a specified div when a button is clicked on the page. I’m trying to do it by calling the specific scrollTo method but it is not working. Here is the function I’m using:
    jQuery("#next_arr").click(function() { jQuery(this).toggleClass('rotate'); jQuery( "#discover_container").slideToggle( "slow" ); jQuery( "#arr_container").slideToggle( "slow" ); jQuery('body').mCustomScrollbar("scrollTo","bottom"); });
    May you help me solving this issue? Thanks so much in advance.

    Reply
    • malihu
      Posted on August 25, 2014 at 02:30 Permalink

      Hi,

      When you say it’s not working, you mean it doesn’t scroll to the “correct” div or it doesn’t scroll at all?

      If it does scroll maybe you need to call the scrollTo method after animations are complete:
      jQuery("#arr_container").slideToggle("slow", function(){ jQuery('body').mCustomScrollbar("scrollTo","bottom"); });

      If it doesn’t scroll at all, check if you get any console errors when opening your page with browser\s developer tools (other errors might prevent the script from executing).

      Reply
      • VamosErik88
        Posted on August 26, 2014 at 09:55 Permalink

        Hi malihu,

        Thanks fro the rapid response. However the issue seems not solved. I tried with the code provided by you but it doesn’t go. The problem is that the body doesn’t scroll at all. I checked the console with the Chrome inspector but there are no errors. Any idea why the scroll is not working? All the other jQuery animations are working except the scroll.

        Reply
        • malihu
          Posted on August 26, 2014 at 22:48 Permalink

          I’m assuming that the #discover_container and #arr_container elements hold content that changes the body length when toggled.

          Since body has a custom scrollbar attached, each time those elements are toggled, the script needs to update the scrollbar according to content length. While the script updates the scrollbar, it’ll interrupt any scrollTo method calls (this is by design).

          It seems that this is the reason your scrollTo method call doesn’t work. The script hasn’t finish updating the scrollbar according to content’s length (which is changing with the toggled elements) and so it prevents the scroll-to bottom animation.

          Since both your slideToggle animation have the same duration (‘slow’) the code I posted should work, but maybe the ‘rotate’ class toggle triggers another CSS3 animation that’s longer than the others.

          In any case, the goal is the same. Call the scrollTo method after all animations are fully done. You could probably add a timeout and do some tests changing the milliseconds value to see when it’ll work. For example:
          setTimeout(function(){ jQuery('body').mCustomScrollbar("scrollTo","bottom"); },700);

          Reply
          • VamosErik88
            Posted on August 29, 2014 at 01:25 Permalink

            Thank you so much man!

            Setting the Timeout to 600 solved the issue and now everything is working flawlessly!

            Check out my website SportAround.me and look how well your scrollbars fits on it! 😉

        • malihu
          Posted on August 29, 2014 at 03:50 Permalink

          Looks great 🙂 Good work!

          Reply
  10. web designer treviso
    Posted on August 20, 2014 at 15:28 Permalink

    The plugin is fantastic .Thanks, I’m using it in many projects

    Reply
  11. Sean
    Posted on August 19, 2014 at 22:57 Permalink

    Maybe I missed the documentation but is there a way to enable scrolling when implementing drag/droping within the div which mCustomScrollbar is applied to? Utilizing Jquery sortable and would like to be able to drag and auto scroll when I drag past the top or bottom of the scroll area.
    Cheers

    Reply
    • Sean
      Posted on August 19, 2014 at 23:43 Permalink

      this is a quick hack I put together although it needs work, right now if I drag over the area it will start scrolling to either the top or bottom determined if I drag past the top or bottom of the area…

      // Hacking the List
      document.onmousedown = docOnMousedown;
      document.onmouseup = docOnMouseup;
      function docOnMousedown(e){
      mouseIsDown = true;
      }
      function docOnMouseup(e){
      mouseIsDown = false;
      }
      $(“#dynamic-list “).mouseleave(function(e) { //Dynamic list is my scrolling windows parent div
      var window = $(this);
      var bottom = window.offset().top + window.outerHeight();
      var top = 0;

      if(e.pageY >= top && mouseIsDown == true){ // dragged past top of parent window
      $(‘#dynamic-list’).mCustomScrollbar(“scrollTo”,”top”,{
      scrollInertia:2000
      });
      }

      if(e.pageY >= bottom && mouseIsDown == true){ // dragged past bottom of parent window
      $(‘#dynamic-list’).mCustomScrollbar(“scrollTo”,”bottom”,{
      scrollInertia:2000
      });
      }
      });
      // Hacking the List

      any ideas? or am I overthinking this….

      Reply
      • Sean
        Posted on August 20, 2014 at 02:00 Permalink

        haha, this is great. Thanks a bunch, tweaking it now but works like a charm!

        Reply
      • Claude
        Posted on September 5, 2014 at 23:26 Permalink

        Hi,

        when I’m trying your solution with jquery UI sortable widget I have the error showing :
        Uncaught Error: Syntax error, unrecognized expression: -=390

        I tried to change the expression by setting a variable s= null and use it like this :
        $(“#list”).mCustomScrollbar(“scrollTo”,s-=moveBy);

        With this I can scroll down 1 time and then nothing happen I still can’t sroll up.

        Could you help me please ?

        PS: Sorry for my bad/weird English that not my first language.

        Reply
        • malihu
          Posted on September 5, 2014 at 23:44 Permalink

          You must use -=/+= as a string or part of string. In your case:
          $("#list").mCustomScrollbar("scrollTo","-="+moveBy);

          In general, the way to use -=/+= is:
          $(selector).mCustomScrollbar("scrollTo","-=100"); $(selector).mCustomScrollbar("scrollTo","-="+var);

          Reply
          • Claude
            Posted on September 6, 2014 at 19:16 Permalink

            I know I should use :
            $(“#list”).mCustomScrollbar(“scrollTo”,”-=”+moveBy);
            but that only return an error :
            Uncaught Error: Syntax error, unrecognized expression: -=190

        • malihu
          Posted on September 7, 2014 at 23:05 Permalink

          Notice the double quotes for -=:
          "-="

          You get the error because you have:
          -=190
          which should be:
          "-="+190

          Reply
  12. Daniele
    Posted on August 19, 2014 at 19:32 Permalink

    Hello,
    When I view ma page with Safari, I get the default scrollbar beside the custom scrollbar. You can see it here: http://www.fondationmarcjurt.ch/biographie.
    What am I doing wrong ?

    Reply
    • Daniele
      Posted on August 19, 2014 at 21:00 Permalink

      Never mind, my bad !
      My div had overflow: auto. I changed it to hidden, and everything is fine !

      Reply
  13. Kevin
    Posted on August 18, 2014 at 16:37 Permalink

    Hi,
    I have noticed that the mcs object is initialized when the scroll event occurs. However, within our application, we need it initialized when the DOM is ready. Is there a way to do this so that mcs is initialized when the DOM is ready?
    The page has several other components and it is not necessarily the case that the scrolling is the first action yet it may be referenced from actions taken on other components on the page.

    Reply
    • malihu
      Posted on August 18, 2014 at 18:43 Permalink

      Hello,

      mcs object is intended to be used with plugin’s callbacks, so in order to be triggered, there has to be a scroll event.
      You could “trick” it though by simply triggering a scroll event (e.g. from -1px to 0) on dom ready and make the mcs object available.
      For example:
      $(document).ready(function(){ $("#content-1").mCustomScrollbar({ setTop:"-1px", callbacks:{ onScroll:function(){} } }).mCustomScrollbar("scrollTo",0,{scrollInertia:0}); setTimeout(function(){ console.log($("#content-1")[0].mcs.top); },150); });

      What this does is:
      a) Sets content initial top position to -1px,
      b) Adds an empty anonymous function to onScroll callback,
      c) Scrolls content to top (0) with zero inertia
      d) Then, after say 150 milliseconds, the mcs object is available: $("#content-1")[0].mcs

      This is a way to trigger mcs on dom ready, but if you simply need to check content’s position, you could easily do:
      $("#content-1 .mCSB_container").position().top; or
      $("#content-1 .mCSB_container")[0].offsetTop;

      Reply
    • Kevin
      Posted on August 22, 2014 at 11:42 Permalink

      Thanks for your help really helped.

      Reply
  14. Mark
    Posted on August 15, 2014 at 16:01 Permalink

    Amazing slider.
    But I have come to a roadblock.
    How do I make the slider responsive for images? I want it to be a horizontal slider and the images height fill out the height of the slider. Also is it possible to have it scale to various screen sizes and devices?

    Mark

    Reply
  15. Max
    Posted on August 15, 2014 at 10:21 Permalink

    I sort of got this to work, but it works quite strangely for me. In order for it to work I have to take out of the top of my html doc or else it just doesn’t work. I can’t get this to work at all with bootstrap framework. Tried putting a custom tool bar encasing an entire grid of the entire page and no custom tool bar appeared. I assigned a width, height and, overflow to the class that I used to enclose the grid and still nothing. I’ve read, re-read and tried, and retired the steps over and over and can’t see anything I am missing. Any tips? I find it very strange that It doesn’t work when I put in my html doc and does without it. Is that normal? Sorry I am very new to this stuff. Thanks for posting this material by the way, it’s very much appreciated.

    Reply
    • Max
      Posted on August 15, 2014 at 10:23 Permalink

      I wrote is what I took out. Not sure why the webpages is taking that away from my sentence.

      Reply
      • Max
        Posted on August 15, 2014 at 10:24 Permalink

        !HTMLDOC type with brackets is what I wrote in the blanks above. posting keeps taking that out.

        Reply
        • malihu
          Posted on August 15, 2014 at 12:57 Permalink

          Hi,
          Post your html doctype/code within code tag:
          <code>html code here</code>

          Reply
          • Max
            Posted on August 16, 2014 at 20:12 Permalink

            I put the code tag as for first line on the top then put !DOCTYPE html right after, and closed all of my code with

            </code>
            . So
            </code>
            tag even encases the tags. When I did this it shifted my page one bar down (not the body but the grid I created with bootstrap framework). So I was left with a white line on the top. It also changed the text to red. However when I take the
            <code>
            tags out and don’t even declare doc type at all it seems to work fine. Kinda strange. Thanks for the help. You are really a great person to be helping so many people with this stuff. I really appreciate it.

          • Max
            Posted on August 16, 2014 at 20:15 Permalink

            I closed my code with code tag*. Where there seems like there is a blank I wrote code in tags.

          • Max
            Posted on August 16, 2014 at 20:57 Permalink

            One thing I noticed as well is when I just use doctype html at top without code tags as I would normally do. When I inspect the element of the page the class is changed to mCustomScrollbar _mCS_1 mCS_no_scrollbar
            as when I remove it the class is mCustomScrollbar _mCS_1. Somehow the normal !doctype is changing this first class name.

          • Max
            Posted on August 17, 2014 at 05:55 Permalink

            Oh, sorry I just noticed what you meant by that. Thought you were referring to do that to my code. My bad.

  16. lazaros
    Posted on August 14, 2014 at 20:15 Permalink

    Hello! I have a problem when i hide the div (it’s a modal) that contains the scrollbar. I want the scrollbar to keep its position but it keeps reseting to top!

    Reply
    • malihu
      Posted on August 14, 2014 at 20:28 Permalink

      This is normal since hiding the modal, means its dimensions become zero (the same would happen with browser’s native scrollbar on any overflowed element).

      To accomplish what you describe, you’d need to write an extra script which will get and store content’s top position before closing the modal and then use plugin’s scrollTo method to scroll-to the (stored) content position when modal is opened again.

      Reply
      • lazaros
        Posted on August 15, 2014 at 09:47 Permalink

        Ok thank you!

        Reply
  17. juju
    Posted on August 13, 2014 at 19:28 Permalink

    Hello,

    I don’t succeed to do appear axis x. I have put on the selector overflow-x: visible; and on the script axis: "x"
    Has someone had already the same problem?

    Thanks.

    Reply
    • malihu
      Posted on August 14, 2014 at 01:18 Permalink

      Does your element have a width set? Does your content expand horizontally? Is your content wide enough to require a horizontal scrollbar?

      If your code works with browser’s native scrollbar, it’ll work with the custom scrollbar too.

      Maybe you need to set the autoExpandHorizontalScroll option parameter to true to automatically expand your inner floated content:
      advanced:{ autoExpandHorizontalScroll: true }

      Reply
  18. sten
    Posted on August 12, 2014 at 23:48 Permalink

    With the new Version UpdateOnContentResize dont work.

    I must before use a Ajaxcall destroy the scrollbar and rebuild after the call.

    Before i dont need destroy the bar first.

    Sorry for my english.

    Reply
  19. Adam Laki
    Posted on August 12, 2014 at 17:29 Permalink

    Hi!

    Firstly, thanks for the great work! Really! 🙂

    Unfortunatly, I’m stucked with my problem. I’d like to use the top/down arrow navigation without clicking in the scrollbar div section. Is there any way to trigger the plugin to be the scrollbar section active (as I see, first I have to click into the section, to use arrow navigation)?

    Thanks for your reply!

    bye,
    Adam

    Reply
    • malihu
      Posted on August 14, 2014 at 01:10 Permalink

      Hello,

      The default way of triggering keyboard navigation is the same as browser’s native scrollbar. This means that the scrollable area must have focus.

      You could do what you describe by adding few lines of code below mCustomScrollbar function call in order to get element focus on mouse-over:
      $(".content").mouseenter(function(){ $(this).focus(); }).mouseleave(function(){ $(this).blur(); });

      This way, when you’re hovering your cursor over the element with the scrollbar you’ll be able to use keyboard keys (like up/down) to scroll its content.

      Reply
  20. Michael Bryzgalov
    Posted on August 10, 2014 at 17:02 Permalink

    It will a better to this plugin will have a offline help reference (HTML or PDF) and header file with externs declarations for Google Closure Compiler (like http://code.google.com/p/closure-compiler/wiki/ExternsForCommonLibraries). Such header file may be used in IntelliJ IDEA or other IDE for IntelliSense.

    Reply
  21. Christian
    Posted on August 8, 2014 at 14:45 Permalink

    Hi,
    is there a way to create a link which links to a different url AND “scrollto”-Position?

    Example:

    test1.html contains a table of Sponsors

    test2.html contains a scroll div listing each Sponsor with details

    Sponsors in test1.html are linked to test2.html and scrollto Position

    Sponsor 5 does not work, if on test1.html.

    Any Idea?

    best
    Christian

    Reply
    • Christian
      Posted on August 8, 2014 at 14:50 Permalink

      <a rel="scrollto-par-5" href="test2.html">Sponsor 5</a>, sorry, forgot to wrap with code

      Reply
    • malihu
      Posted on August 8, 2014 at 15:50 Permalink

      This would work the same way as if you didn’t have a custom scrollbar. For example you’d have to use a hash in your link’s href (e.g. test2.html#/sponsor-5). Then a script would get the hash (sponsor-5) and invoke a scrollTo method on say #sponsor-5 (which could be an element id):
      $(selector).mCustomScrollbar("scrollTo","#sponsor-5");

      Reply
    • malihu
      Posted on August 8, 2014 at 19:21 Permalink

      Code example:

      After invoking the plugin in your page, e.g.:
      $(".content").mCustomScrollbar();

      Get location hash (e.g. #/sponsor-5) from URL (e.g. test2.html#/sponsor-5) and remove slash:
      var to=window.location.hash.replace("/","");
      variable to becomes #sponsor-5

      Scroll-to element with id sponsor-5 which exists inside your scrollable div (e.g. .content):
      $(".content").mCustomScrollbar("scrollTo",to);

      Reply
  22. Wendi
    Posted on August 7, 2014 at 21:32 Permalink

    hi there! i love this control and have used it plenty. I am currently having trouble seeing the scrollbar if the page url has an anchor tag in it.

    for instance:

    visit http://www.shfm-online.org/2014-wednesday

    click the link “Jerry White” in the content text area.

    on the next page, the anchor finds the right place within the text, but the scrollbar is nto visible. you can see it here w/o the anchor:

    http://www.shfm-online.org/2014-presenters

    i am using Version: 3.0.3 and my code is

    (function($){ $(document).ready(function() { $(".mCustomScrollbar").mCustomScrollbar(); }); })(jQuery); i've tried using the "scrollTo" feature, to no avail. any suggestions?

    Reply
    • malihu
      Posted on August 8, 2014 at 07:14 Permalink

      You need to include the plugin files: jquery.mCustomScrollbar.css and jquery.mCustomScrollbar.concat.min.js in your page (see “How to use it” section above).
      When this is done, you need to use the scrollTo method to scroll-to #jwhite position:
      $(".mCustomScrollbar").mCustomScrollbar("scrollTo","#jwhite");

      Reply
  23. Topogigio
    Posted on August 7, 2014 at 12:39 Permalink

    Is there any way to include just a theme in css? 53 KB are quite large…

    thanks

    Reply
  24. mano
    Posted on August 6, 2014 at 19:04 Permalink

    Hi, great plugin!

    I want to ask whether it is possible to somehow bind hotizontal scrolling to deltaX and vertical scrolling to deltaY only. Thanks.

    Reply
  25. Todd Fletcher
    Posted on August 5, 2014 at 20:13 Permalink

    I see a few others have a problem with ‘mCS_no_scrollbar’. I have the same issue. I guess that because I am loading the div content via AJAX, that when the scrollbar is loaded there is nothing in the div… after which the section loads and the nifty scrollbar is not display?

    I see there is a way to force the scrollbar to always show. However, I have not been able to get that to work. Any help?

    Reply
    • malihu
      Posted on August 6, 2014 at 03:38 Permalink

      Hello,

      The first thing to check is if your element has a height or max-height set. This is essential for the scrollbar (any scrollbar) to function.

      The second thing is where and how you’re loading your content. If the scrollbar is initialized before your ajax call, you need to load your content inside the .mCSB_container div and not directly in your element, e.g.:
      $(".content .mCSB_container").append(data)

      The plugin archive contains an ajax example in case you need to check its source: http://manos.malihu.gr/repository/custom-scrollbar/demo/examples/ajax_example.html

      Reply
  26. Andrey
    Posted on August 5, 2014 at 16:24 Permalink

    Hi! I have problem with dragging slider, it doesn’t work in IE11. How I can solve this problem?

    Thanks.

    Reply
    • malihu
      Posted on August 6, 2014 at 03:45 Permalink

      Hi,
      The plugin works well in IE (you can verify it by checking all demos and examples scrollbar functionality in IE). Your issue with IE11 is probably CSS related(?). In any case, I can’t really help unless I see your page online.

      Reply
  27. vijayan
    Posted on August 5, 2014 at 14:02 Permalink

    Hi,

    I have two horizontal scroll, here my question is
    Once complete the first horizontal scroll automatically page will scroll and now targeting the second scroll (i mean page vertical scroll).

    How can i implement the scrollTo function.

    Thanks & regards,
    Vijayan M

    Reply
    • malihu
      Posted on August 6, 2014 at 03:57 Permalink

      Hello,

      I don’t really know what you’re trying to do, but info on implementing the scrollTo method you can find here and in plugin examples:
      http://manos.malihu.gr/repository/custom-scrollbar/demo/examples/scrollTo_demo.html

      If you want to stop page scrolling after your element scrolling is complete, you need to set the mouseWheel preventDefault option parameter to true, e.g.:
      $(selector).mCustomScrollbar({ mouseWheel:{ preventDefault:true } });

      Reply
      • vijayan
        Posted on August 6, 2014 at 15:14 Permalink

        Hi,

        Thanks for reply. I fixed the problem its working fine and this is my Code:

        callbacks: { onTotalScroll: function () { $('html, body').scrollTop(1705); } }

        instead of the this line – $(‘html, body’).scrollTop(1705);

        i used – $(‘html, body’).animate({scrollTop:$(this.hash).offset().top}, 1705);

        but the smooth scroll not happened.
        How can i smooth page scroll.

        Thanks & regards,
        Vijayan M

        Reply
        • malihu
          Posted on August 7, 2014 at 06:20 Permalink

          My guess is that you probably need to do:
          (‘html, body’).animate({scrollTop:1705}, 1000);
          Where 1705 is the position and 1000 the animation duration in milliseconds (1 sec).

          $(this.hash).offset().top would need to be used inside a click event where this would be a link object.

          Reply
          • vijayan
            Posted on August 7, 2014 at 10:23 Permalink

            Thanks malihu

            this is my code
            $('html, body').animate({scrollTop:$(".step2-container").offset().top-80},1500);

            its working fine 🙂

  28. agha
    Posted on August 5, 2014 at 11:37 Permalink

    Hi, thank you very much. the scrollbar works like a charm, but how can I
    make the scrollbar visible only on scroll event (I mean when the mouse wheel moves or the pointer is exactly on the scrollbar). I don’t want it to become visible when the mouse pointer is on the Element.

    Reply
    • malihu
      Posted on August 5, 2014 at 15:10 Permalink

      Hi,

      You’ll need to edit the CSS file. More specifically in “6. SCROLLBAR COLORS, OPACITY AND BACKGROUNDS” you should remove:
      .mCS-autoHide:hover > .mCustomScrollBox > .mCSB_scrollTools, .mCS-autoHide:hover > .mCustomScrollBox ~ .mCSB_scrollTools
      which is few lines below.

      The dynamic class applied to the scrollbar when it’s scrolling the content is: .mCSB_scrollTools_onDrag

      Reply
  29. Jeroen Vorsselman
    Posted on August 1, 2014 at 16:49 Permalink

    Hello!
    This plugin looks beautiful!

    But how can i place the scrollbar inside an existing element?

    I’ve got a element with a fixed size but the height of the element can change. I need the scrollbar to have a absolute position inside the element instead of having a scrollbar next to it.
    Can i do this with pure css or did i miss a property that needs to be set?

    Reply
    • Jeroen Vorsselman
      Posted on August 1, 2014 at 17:38 Permalink

      I updated the fiddle to show what i mean:

      http://jsfiddle.net/f8w8v/12/

      Reply
    • malihu
      Posted on August 2, 2014 at 04:39 Permalink

      You’d need to give your element at least max-height value (without a height or max-height a scrollbar, any scrollbar, cannot work).

      You can change the positioning of the scrollbar (which has position:absolute) itself via the CSS file and via the scrollbarPosition option parameter.

      Reply
  30. Alex Lutz
    Posted on July 31, 2014 at 15:08 Permalink

    Good job, great plugin, Thank You!

    Reply

Comments pages: 1 50 51 52 53 54 85

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