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

Post a comment

Comments pages: 1 68 69 70 71 72 85

  1. Tennis fan
    Posted on November 6, 2015 at 13:43 Permalink

    First thank you for your great plugin !

    I use 2 horizontal scrollbars for a div (1 scroll bottom and 1 top) with the technic explained there : http://stackoverflow.com/questions/3934271/horizontal-scrollbar-on-top-and-bottom-of-table

    In my case I have in “whileScrolling” event of both scrollbar:

    position = this.mcs.leftPct; sScroll.mCustomScrollbar("scrollTo", position + "%", {callbacks:false});

    Notice that “sScroll” is the selector of the other scrollbar.

    So when a scrollbar is scrolling, we force scrolling the other. I use pourcentage because this.mcs.draggerLeft doesn’t work.

    It works (a bit) but scrollbar don’t follow in the right way.

    Have you a better solution for having 2 horizontal scrollbar (top & bottom) following each other ?

    Reply
    • malihu
      Posted on November 6, 2015 at 14:17 Permalink

      Hello,

      You could use this.mcs.left and probably set scrollTo method timeout to zero (default is 60 milliseconds). I’d also suggest setting method’s scrollEasing option to "easeOut" to make it identical to the standard scrolling animation:

      position = this.mcs.left; sScroll.mCustomScrollbar("scrollTo", position, { callbacks:false, timeout:0, scrollEasing:"easeOut" });

      Reply
      • Tennis fan
        Posted on November 6, 2015 at 15:10 Permalink

        Wow thank you so much ! It works great !

        My last problem is to change all scrollbars when a div is hover.

        I tried to set background of scrollbar when the div capture “mouseenter” event and back color to normal when “mouseleave”.
        It works but then the hover of the scrollbar doesn’t work anymore.
        Code :

        sDiv.on("mouseenter", function(){ $(".mCS-theme.mCSB_scrollTools .mCSB_dragger .mCSB_dragger_bar").css("background-color", "#1997c6"); $(".mCS-theme.mCSB_scrollTools .mCSB_dragger .mCSB_dragger_bar").css("background-color", "rgba(25, 151, 198, 0.85)"); }).on("mouseleave", function(){ $(".mCS-theme.mCSB_scrollTools .mCSB_dragger .mCSB_dragger_bar").css("background-color", "#4F4F4F"); $(".mCS-theme.mCSB_scrollTools .mCSB_dragger .mCSB_dragger_bar").css("background-color", "#rgba(79, 79, 79, 0.5)"); });

        My other solution was to force a “mouseover” on my scrollbars but it didn’t succeed.

        So what is the best way to force “mouseover” on a scrollbar ?

        Thank you again for your last answer (very helpful !)

        Reply
        • malihu
          Posted on November 6, 2015 at 18:19 Permalink

          I think hover doesn’t work because the inline CSS, which is the one added by jQuery, overwrites all others. I’d suggest toggling a class instead of applying the background-color style directly, so everything works as expected. For example:

          JS:

          var draggerBar=$(".mCS-theme.mCSB_scrollTools .mCSB_dragger .mCSB_dragger_bar"); sDiv.on("mouseenter", function(){ draggerBar.addClass("sDiv-hover"); }).on("mouseleave", function(){ draggerBar.removeClass("sDiv-hover"); });

          CSS:

          .mCS-theme.mCSB_scrollTools .mCSB_dragger .mCSB_dragger_bar.sDiv-hover{ background-color: #1997c6; }

          Does this make sense for what you want to do?

          Reply
          • Tennis fan
            Posted on November 6, 2015 at 19:42 Permalink

            Excellent !

            You’re right I was not using the right way to change the background-color.

            Thank you se much for your plugin and your time.

    • malihu
      Posted on November 10, 2015 at 17:39 Permalink

      An update on double scrollbars:

      I’ve just released plugin version 3.1.2 so you can re-download it as it fixes some potential issues with horizontal scrollbar resizing.

      I’ve also created an example of double horizontal scrollbars here:
      http://manos.malihu.gr/repository/custom-scrollbar/demo/examples/double-horizontal-scrollbar-example.html

      In this example, the code is simplified without extra markup/dummy elements and no scrollTo method which works much better. Everything is done within mCustomScrollbar function call and the demo code is:

      $(".wrapper").mCustomScrollbar({ axis:"x", callbacks:{ onInit:function(){ var $this=$(this), cloned=$this.find(".mCSB_scrollTools").clone(true).addClass("mCSB_scrollTools-clone"); $this.find(".mCSB_scrollTools").parent().append(cloned); $this.data("scrollbar",{ top:$this.find(".mCSB_scrollTools-clone .mCSB_dragger"), bottom:$this.find(".mCSB_scrollTools:not(.mCSB_scrollTools-clone) .mCSB_dragger") }); }, onUpdate:function(){ $(this).data("scrollbar").top.css("width",$(this).data("scrollbar").bottom.width()); }, whileScrolling:function(){ $(this).data("scrollbar").top.css("left",this.mcs.draggerLeft); } } });

      Reply
  2. leomn
    Posted on November 6, 2015 at 11:06 Permalink

    Hi,malihu,can you help me?
    It doesn’t work When I call a scrollTo method and set the position parameter to be an element selector,actually it scrolls to the bottom.
    And when set to be a specific number of pixels(i.e. integer values),it scrolls to an unexpected position,depend on the height of my content.

    Reply
    • malihu
      Posted on November 6, 2015 at 11:17 Permalink

      It should normally work, so I can’t really help unless I see your page/code (can you send me a link?). Maybe some element requires a CSS position value(?)

      Reply
      • leomn
        Posted on November 6, 2015 at 14:21 Permalink

        Please complete the security check to access malihu.gr

        Reply
      • leomn
        Posted on November 6, 2015 at 14:23 Permalink

        I get a wrong page every time the comment contains code,why?

        Reply
      • leomn
        Posted on November 6, 2015 at 14:49 Permalink

        Let me try to post some idle code,I’m sorry for your any inconenience..
        <body>why?</body>

        Reply
      • leomn
        Posted on November 6, 2015 at 14:56 Permalink

        I tried on another computer,and this time it works well in the first case,but scrolls to the bottom in the other case.My code is as follow:
        HTML <body> <div class="content" style="width: 100px; height: 200px; overflow: auto;"> <div> <div class="scale"> 20px </div> <div class="scale"> 40px </div> //A long list of "scale"... <div id="scrollHere" class="scale scrollHere">//Notice this 300px </div> //A long list of "scale"... </div> </div> <button style="width:30px;height:20px;"></button> </body>

        Reply
      • leomn
        Posted on November 6, 2015 at 14:58 Permalink

        Thanks godness! CSS and JS below

        .scale { height: 19px; border-bottom: 1px solid; } $(document).ready(function () { $(".content").mCustomScrollbar(); $("button").click(function () { $(".content").mCustomScrollbar("scrollTo", ".scrollHere");//works well $(".content").mCustomScrollbar("scrollTo", 400);//scroll to the bottom }); });

        Reply
        • leomn
          Posted on November 6, 2015 at 15:00 Permalink

          The list is long enough ,much longer than 400px.

          Reply
        • malihu
          Posted on November 6, 2015 at 17:23 Permalink

          OK I think the issue is because of the button element getting the focus (while clicked) and the scrollbar scrolling automatically to the focused element (the button itself!).

          You need to use the autoScrollOnFocus option parameter and remove the button selector from its value:

          $(".content").mCustomScrollbar({ advanced:{ autoScrollOnFocus: "input,textarea,select,datalist,keygen,a[tabindex],area,object,[contenteditable='true']" } });

          Reply
          • leomn
            Posted on November 6, 2015 at 19:38 Permalink

            Thank you! It’s very kind of you.

  3. Ryan Park
    Posted on November 6, 2015 at 08:20 Permalink

    I want to make scrollbar element always exist even if content is not long enough to use scrollbar. Is it possible?

    Reply
    • leomn
      Posted on November 6, 2015 at 10:42 Permalink

      See alwaysShowScrollbar: int

      Reply
      • Ryan Park
        Posted on November 6, 2015 at 10:56 Permalink

        thank you leomn!

        Reply
  4. Ryan Park
    Posted on November 5, 2015 at 22:14 Permalink

    Dear Malihu, I have a trouble. But I’m not good at english,,so you’d better check this youtube video..

    the contents was changed yet ‘mCS_no_scrollbar’ didn’t be removed and your scrollbar didn’t appear.
    how can I fix this problem?

    Reply
    • Ryan Park
      Posted on November 5, 2015 at 22:15 Permalink

      plz check this video
      https://youtu.be/kg_bvVKW9kU

      Reply
    • Ryan Park
      Posted on November 5, 2015 at 22:44 Permalink

      Actually, the code $(xxx).mCustomScrollbar(xxx); executed everytime modal window opened

      Reply
    • malihu
      Posted on November 5, 2015 at 22:59 Permalink

      Hello,

      How do you change the content of the modal? With javascript? Can you send me your code?

      Reply
    • Ryan Park
      Posted on November 6, 2015 at 06:14 Permalink

      I’m using AngularJS for controlling MVC model..
      In Controller, ‘$scope.tmodal_intro’is binding with the element’s value.
      in the method $scope.setTmodal(), $scope.tmodal_intro = $scope.tutors[index].intro;
      $scope.tmodal_intro is updated like above and AngularJS automatically apply this change to DOM.
      AngularJS always scanning the controller, then it detect the change and update related DOM element.
      My code is too complicated, so I will make some simple example with angularJS and bootstrap for you.

      Reply
    • Ryan Park
      Posted on November 6, 2015 at 07:27 Permalink
      • malihu
        Posted on November 6, 2015 at 11:14 Permalink

        You need to either set/update the content inside the .mCSB_container which is inside the .content element or apply the scrollbar on .modal-body instead.

        I’ve modified the files to apply the scrollbar on .modal-body (tested and fully working). I sent you the modified files (index.html, script.js and style.css) by email.

        Reply
        • Ryan Park
          Posted on November 6, 2015 at 12:11 Permalink

          Thank you so much! It works!

          Reply
  5. Sebastian
    Posted on November 5, 2015 at 00:01 Permalink

    The X Scroll is not working with mac trackpad or magic mouse.
    With a PC gamer mouse its working fine.

    Any suggestions? i didnt find any options to help me with this problem

    Thank you

    Reply
    • malihu
      Posted on November 5, 2015 at 20:36 Permalink

      Do you mean on elements with both vertical and horizontal scrollbars?

      Reply
  6. Dave Amour
    Posted on November 4, 2015 at 16:07 Permalink

    Hi

    I have an issue where resizing is not quite right. If I am running two monitors and monitor 1 is a smaller resolution than monitor 2 and I drag my browser window from monitor 1 to monitor 2 then there is a gap at the bottom. I am assuming the code has cached some available sizes from monitor 1 rather than re-reading them when needed.

    Any thoughts on this?

    Thanks

    Reply
    • malihu
      Posted on November 4, 2015 at 16:43 Permalink

      Can’t really say why this happens as I’ve never experience it before… The script does not cache any sizes as it’s checking them in real-time every few milliseconds.

      When you say “gap at the bottom” what exactly happens? Is there an empty scrollable gap? Does this happen only when dragging between monitors or by resizing the browser as well?

      Reply
  7. sc
    Posted on November 3, 2015 at 16:06 Permalink

    Using your scrollbar in my site and thought it was running great, however, I have found some more of my code further down the header section that’s not being run at all. Seems like anywhere down from where I include the jquery.mCustomScrollbar.js, or the minified version, in my header block then it doesn’t run.

    I’m not getting any errors or anything reported in the browser and I can’t think why it is failing. Moving the including of your code right down to just before the end of the body tag would fix things but then I got lots of other errors where I’m calling it in $(document).ready(function() { })

    I’m running jQuery 1.11.2 and the latest version of your scrollbar. I know you will ask for code or errors, but I’m fitting it into an existing site which is rather complicated and it seems to work standalone on the demo pages.

    Any ideas how I can debug this, or any thoughts on what would be causing it? As far as I can see it just loads the scrollbar code and then stops, ignoring everything else following. Do I really need to add it right at the bottom of the page for reasons other than performance? Would love to sort this out because otherwise it’s fantastic and is just the job.

    Thanks in advance.

    Reply
    • malihu
      Posted on November 3, 2015 at 16:28 Permalink

      No you can add it anywhere you want as any other plugin script. This might be related to something else(?) but I cannot help unless I see your page/code. Can you send me a link?

      Reply
    • malihu
      Posted on November 3, 2015 at 16:30 Permalink

      Do you run other libraries in addition to jQuery (e.g. prototype.js)?

      Reply
    • sc
      Posted on November 5, 2015 at 16:31 Permalink

      Apologies, but it seems to have fixed itself now.

      Can I ask you another question which I am puzzling over? I’ve a jquery sortable list inside your scrollbar. When I drag an item to the top of the list it doesn’t automatically scroll upwards. Could this be programmed do you know, or is there a setting somewhere? Detecting when you’ve hit the top and then scrolling the scrollbar is proving tricky.

      Reply
  8. harshil
    Posted on November 2, 2015 at 14:31 Permalink

    Hi,

    I love your custom scrollbar, however I am trying this one thing which I can’t seem to get working. I have these “” tabs of a huge table which is scrolled through using your scrollbar. Now when I am using tab to traverse, the horizontal scroll seem to move faster because of more width of each tab (than height) and the bottom one moves slower, so the content gets hidden. I was hoping if I could know about an option where it is possible to have two different snapAmounts (x-axis and y-axis). Or any other work around.

    Please note, I have triggered a fixed table headers and left bar using the callback scroll function.

    Reply
    • malihu
      Posted on November 2, 2015 at 20:02 Permalink

      There’s no option for different y/x snapAmount but if you could send me a link in order to understand better what you’re trying to do, I might be able to help with a workaround.

      Reply
      • harshil
        Posted on November 3, 2015 at 07:27 Permalink

        https://www.diigo.com/item/image/5a2ja/r4c0

        As you can see, I am navigating the green center tabs using arrows. The scrollbar moves faster when moved to bottom hence the tab goes underneath while the snapamount for horizontal movements are perfect.

        The table column on the right is to fixed using the callback function onscroll.

        Reply
        • harshil
          Posted on November 3, 2015 at 12:00 Permalink

          Hey thanks for contacting me. I solved it by assigning
          $(selector).mCustomScrollbar(“scrollTo”,position,options);
          to each of the keys I had binded arrows to.

          Reply
          • malihu
            Posted on November 3, 2015 at 15:28 Permalink

            Cool! I’ll push an update to 3.x branch (plugin development version) that’ll feature different snapAmount values for each axis (e.g. snapAmount:[50,100] for 50px vertical and 100px horizontal). I’ll push the update by tomorrow so you can check it out if you want.

          • harshil
            Posted on November 3, 2015 at 15:45 Permalink

            Thanks. I will check.

  9. Weas
    Posted on November 1, 2015 at 08:36 Permalink

    The scroll bar seems to work fine in most cases but I have a div that contains images with CSS property set to inline-block, and no-whitespace in order to get a horiz scroll bar of images. It works fine as long as I don’t enable the plugin but as soon as I do, all those images sizes get adjusted (really huge). It only happens when I set the no-whitespace property and I can’t think of an y other way to get the effect I want without that being set (a div with a horiz scroll bar filled with images)

    Reply
    • malihu
      Posted on November 1, 2015 at 17:36 Permalink

      Can you post the CSS or send me a link/jsFiddle?
      Normally, the following example will work:

      HTML

      <div class="mcs-horizontal-example"> <img src="..." class="item" /> <img src="..." class="item" /> <img src="..." class="item" /> <!-- and so on... --> </div>

      CSS

      .mcs-horizontal-example{ overflow-x: auto; white-space: nowrap; } .mcs-horizontal-example .item{ display: inline-block; }

      JS

      $(".mcs-horizontal-example").mCustomScrollbar({ axis:"x" //,advanced:{autoExpandHorizontalScroll:true} //uncomment/enable for dynamic content });

      Reply
      • Weas
        Posted on November 4, 2015 at 08:47 Permalink

        You fixed my issue, thank you so much not only for that but for making this wonderful plugin.

        Reply
  10. Ryan Morris
    Posted on October 29, 2015 at 20:49 Permalink

    Hey, first of all I just want to say you’ve built an amazing plugin!

    Now, my question is there any way to have the buttonUp / buttonDown arrows to have mobile click functionality? As in, lets say the user doesn’t want to click the scroll bar or click and drag and instead wants to use the teeny tiny up and arrow keys to navigate. From what I’ve messed around with I can’t seem to find a way to have it listen correctly. Thanks in advance!

    Reply
    • Ryan Morris
      Posted on October 30, 2015 at 01:24 Permalink

      Figured it out, realized it needed to be a ‘stepless’ type instead of a ‘stepped’. Not too certain on as to why though. Didn’t spend too much time researching why the button struggles to click if set as a ‘stepped’ but works like a charm as ‘stepless’.

      Reply
  11. timme77
    Posted on October 28, 2015 at 15:54 Permalink

    I have enabled the plugin on my website. I chose for the horizontal scrollbar and everything seems to work perfectly. When i checked my website in chrome and safari there is an issue though. When i move the scrollbar it seems to flicker. Any idea what causes this problem?

    Thanks for your reply.

    Reply
    • malihu
      Posted on October 28, 2015 at 21:33 Permalink

      I can’t really say without viewing your website… Can you send me a link?

      Reply
  12. Aleksandar
    Posted on October 28, 2015 at 15:15 Permalink

    Is there any way to include any “sticky” library in mCustomScrollbar?

    I need heading on each of my paragraphs to be fixed to the top of the page while i am scrolling.
    I tried with Sticky-Kit (http://leafo.net/sticky-kit/) but it seams that the library did not catch the event when something is out of view.

    Reply
    • malihu
      Posted on October 28, 2015 at 21:31 Permalink

      I’m not sure Sticky-Kit or other similar scripts will work with the custom scrollbar, because they usually use browser’s native/default scrollbar events. CSS fixed position should work with the custom scrollbar though.

      Reply
      • Aleksandar
        Posted on October 29, 2015 at 14:10 Permalink

        I presume that i need to make that in “whileScrolling” callback.

        Can you please share with us how is the best way to approach this?

        Thanks

        Reply
        • malihu
          Posted on October 30, 2015 at 01:29 Permalink

          Sure.
          If you want to do it programmatically you can use whileScrolling callback as you said 🙂
          It all depends on the functionality you need but a simple example would be:

          Assuming you have the following element in your scrollable content:

          <div id="sticky">sticky content</div>

          You give it the following CSS:

          #sticky{ position: absolute; top: 0; }

          Then in your mCustomScrollbar you can do:

          $(selector).mCustomScrollbar({ callbacks:{ whileScrolling:function(){ $("#sticky").css("top",-this.mcs.top); } } });

          The above will make it stick to zero position. The calculation is done easily using the mcs object (see more info in “Returning values” section of User-defined callbacks).

          To give it an offset, simply add a margin-top value in the CSS, e.g. margin-top: 30px;

          You can of course create more advanced sticky elements by doing various calculations in whileScrolling callback (e.g. using mcs object) but it depends on how you want the sticky element to function.

          Reply
  13. Max
    Posted on October 28, 2015 at 11:57 Permalink

    Hi, i’m not sure, maybe i’ve just missed this in APi, but how can i make plugin to scorll at point where i clicked on scrollbine line; i mean when you clicking on OS default scroll it’s goint to same position of page where you clicked on scroll-bar

    Thanks 🙂

    Reply
    • malihu
      Posted on October 28, 2015 at 21:50 Permalink

      Normally when clicking on browser’s default scrollbar it scrolls by a fixed amount each time (not to the same position you clicked). It appears that it scrolls to the same position because it keeps scrolling while mouse button is being pressed (until it reaches the cursor position). The difference with the custom scrollbar is that it scrolls by click (not repeatedly by pressing the mouse). I’ll probably change the event at some future version to match the default browser’s scrollbar.

      Reply
  14. GBastos
    Posted on October 27, 2015 at 18:33 Permalink

    Hello, firstly I’d like to congrats you, this plugin is very useful.
    I’m trying use it with horizontal scroll, but it doesn’t work 🙁

    Look my code:
    <div class="row div-scroll-horizontal"> <!---- In that class I put overflow-x: auto ---> <ul id="thumblist" class="list-inline img-thumbs" > <li class="image-list"><a href="#" class="bullet-image"><img src="../images/image1.png" data-imageName='image1.png' class="img-lista" title="RG Frente"></a></li> <li class="image-list"><a href="#" class="bullet-image"><img src="../images/image2.png" data-imageName='image2.png' class="img-lista" title="RG Verso"></a></li> <li class="image-list"><a href="#" class="bullet-image"><img src="../images/image1.png" data-imageName='image1.png' class="img-lista" title="RG Frente"></a></li> <li class="image-list"><a href="#" class="bullet-image"><img src="../images/image2.png" data-imageName='image2.png' class="img-lista" title="RG Verso"></a></li> <li class="image-list"><a href="#" class="bullet-image"><img src="../images/image1.png" data-imageName='image1.png' class="img-lista" title="RG Frente"></a></li> <li class="image-list"><a href="#" class="bullet-image"><img src="../images/img1.jpg" data-imageName='img1.jpg' class="img-lista" title="RG Verso"></a></li> <li class="image-list"><a href="#" class="bullet-image"><img src="../images/Desert.jpg" data-imageName='Desert.jpg' class="img-lista" title="RG Frente"></a></li> <li class="image-list"><a href="#" class="bullet-image"><img src="../images/img1.jpg" data-imageName='img1.jpg' class="img-lista" title="RG Verso"></a></li> <li class="image-list"><a href="#" class="bullet-image"><img src="../images/Desert.jpg" data-imageName='Desert.jpg' class="img-lista" title="RG Frente"></a></li> <li class="image-list"><a href="#" class="bullet-image"><img src="../images/image2.png" data-imageName='image2.png' class="img-lista" title="RG Verso"></a></li> </ul> </div>

    I apreciate any help 🙂

    Reply
    • malihu
      Posted on October 27, 2015 at 19:55 Permalink

      Are you using latest plugin version (3.1.x)? Can you post your CSS?

      If your list-items are floated left, you should probably need to enable autoExpandHorizontalScroll option (info)

      advanced:{ autoExpandHorizontalScroll: true }

      Reply
  15. Tyler
    Posted on October 27, 2015 at 01:57 Permalink

    First of all, thanks for writing such a great plugin!

    My use case might be a little different than what you’re used to. 🙂 Basically, I would like to decouple the scrollbar from scrollable content and instead to use it as a “zoom” feature for an image cropper. Is this decoupling possible? I’ve looked through the API and either I completely missed what I’m looking for or it just never clicked.

    I’ve been able to wire the arrow buttons to the cropper API using some javascript when I initiate the scrollbar, but I would like to have a fixed number of clicks for the dragger bar to move across the dragger rail. Here’s what I’ve got so far:
    $(‘#zoomSlider’).mCustomScrollbar({
    theme: “rounded-dark”,
    axis: “x”,
    autoDraggerLength: false,
    //advanced: { autoExpandHorizontalScroll: true },
    //setWidth: “269”,
    alwaysShowScrollbar: 2,
    scrollbarPosition: “outside”,
    scrollButtons: {
    enable: true,
    scrollAmount: 1
    }
    });

    What changes can I make to get approximately 6 clicks in either direction from 0% to 100%? (I’ve managed to get everything working correctly except for this….)

    Thanks!

    Reply
  16. Nick
    Posted on October 26, 2015 at 12:33 Permalink

    Hi Malihu,

    Great job with this plugin, congrats!
    I’m trying to integrate it with a vertical scrollbar inside a carousel slide, and the issue I’m getting in is that on mobile the custom scrollbar prevents horzizontal swiping, so I can no longer swipe to the next carousel item. On desktop, mouse-swiping works great (mouse events are bubbling), but it seems like the touch events are not bubbling.
    Check out this example: http://jsfiddle.net/tkzvzp54/5/embedded/result/.
    Is there any easy way to allow horizontal swipe on a container with a vertical scrollbar?

    Thanks,
    Nick

    Reply
  17. Nathaniel
    Posted on October 23, 2015 at 19:09 Permalink

    The themes are great for the custom scroll bar! The problem I’m experience is that touch swiping is completely broken when using this plugin. I am using a Microsoft Surface Pro 3.

    Touch swiping does not work. Only if I scroll with my mouse and then swipe while the scroll is already in action does it work.

    my code:
    $.mCustomScrollbar.defaults.scrollButtons.enable = true; //enable scrolling buttons by default $(".table__wrapper").mCustomScrollbar({ theme: "rounded-dots-dark", scrollInertia: 400, scrollButtons: { scrollAmount: 10, snapAmount: 100, contentTouchScroll: 25 } }); $(".table__wrapper").on("mousewheel", function (e, delta) { e.preventDefault(); $(".table__wrapper .mCustomScrollBox").trigger("mousewheel", [delta]); });

    Reply
    • Nathaniel
      Posted on October 23, 2015 at 19:23 Permalink

      Update – apparently touch scrolling works on Chrome – but does not work on IE11 or Edge.

      On firefox, the touch scrolling only barely moves a few pixes – where on Chrome, it scrolls as intended. Any solution for cross browser touch scrolling?

      Reply
      • malihu
        Posted on October 23, 2015 at 19:51 Permalink

        This is a known issue with IE and Edge browsers on some hybrid devices (for example on Windows phone it works as expected). I’m trying to solve this but it takes a bit longer as I don’t have such device for testing.

        Reply
        • Nathaniel
          Posted on November 5, 2015 at 20:28 Permalink

          There is a bug on Firefox using Surface Pro 3. When browser is “full screen”, touch scrolling/swiping the content completely does not work. It only highlights the text. When full screen is disabled, touch scrolling/swiping works fine.

          Reply
  18. Paul
    Posted on October 23, 2015 at 02:22 Permalink

    Hi, great article here! I am using this plugin on a website, and for the most part it works great. However, there isn’t very great control over the trackpad/touch swipe of the vertical scroll bar. i.e I am not able to stop the scroll in a position while I scroll, it kind of lags and drags a long and sometimes is just completely not scrolling as it should. I adjusted the “scrollInertia” property of the scrollbar, but it did not help much. Any thoughts?

    Reply
  19. invsm
    Posted on October 21, 2015 at 22:33 Permalink

    Hi!
    scrollTo (by id) does not always scroll to the top of the element. Sometimes it stops a few px under or above the element.
    What could be the reason?

    Reply
    • malihu
      Posted on October 27, 2015 at 20:06 Permalink

      I’d have to see your page/code in order to help. Is your content fully loaded before using scrollTo method?

      Reply
  20. Chan
    Posted on October 21, 2015 at 16:17 Permalink

    Am i right that searching for “a string” ctrl+f cmd+f is not jumping to its position, also if it is not visible on the current scroll position?

    Reply
    • malihu
      Posted on October 21, 2015 at 17:32 Permalink

      Searching with Ctrl/cmd+f will briefly disable the scrollbar and content will scroll/jump to the string. Initiating a scroll again (e.g. via mouse-wheel) will re-enable the custom scrollbar.

      Reply
      • Chan
        Posted on October 22, 2015 at 09:48 Permalink

        do i have to implement this, or is this functionality of your plugin. Because at the moment it is not working.

        Reply
        • malihu
          Posted on October 22, 2015 at 22:49 Permalink

          It’s a plugin functionality. Do you test it on Firefox? I can see it working on Chrome, IE, Opera etc.

          Reply
          • Chan
            Posted on October 23, 2015 at 09:50 Permalink

            Can you provide an example, cause’ it is also not working on your demo page for me. (Chrome)

        • malihu
          Posted on October 23, 2015 at 19:47 Permalink

          Which plugin version are you using?

          Example:
          Go to this example. Hit Ctrl+f and search for the string “Quis autem”. The string(s) should be visible and highlighted in the content.

          Reply
          • Chan
            Posted on October 28, 2015 at 12:14 Permalink

            No sry, this one is not working either chrome or firefox (using macOSX). Of course, i was trying to search via cmd-f for “End of content.”

        • malihu
          Posted on October 28, 2015 at 22:53 Permalink

          Can you try again the example? It uses the latest plugin version.

          Reply
          • Chan
            Posted on October 30, 2015 at 09:45 Permalink

            No sry, nothing changed. Still not useable with FF or Chrome (macOSX)

          • Chan
            Posted on November 3, 2015 at 09:52 Permalink

            Something new? It should be easy reproducible.

        • malihu
          Posted on November 3, 2015 at 16:39 Permalink

          The thing is that I cannot reproduce the issue.

          I’ve tested it on Windows and OSX (Yosemite) in Safari (8), Chrome (46) and latest Firefox. It works in all browsers except Firefox, which is something that cannot be fixed as it’s about how Firefox prevents scrolling on hidden elements.
          In every other browser it does work when I test it.

          Reply
      • Chan
        Posted on October 22, 2015 at 10:02 Permalink
  21. webbieram
    Posted on October 20, 2015 at 17:18 Permalink

    Hi Malihu,
    i m using ajax in my website and injecting content only while user clicking on menu item. Some times it is updating perfectly and but some times it was not working. Is there any refresh event for the plugin. I have gone through the plugin documentation but unable to find a proper way.

    Also i tried to recall the plugin through ajax success event but it is also not working well.

    Please remember it was working well at some points and some times not.

    Reply
    • webbieram
      Posted on October 20, 2015 at 17:27 Permalink

      actually the scroll bar is missing while the user populating another group

      Reply
    • malihu
      Posted on October 20, 2015 at 23:38 Permalink

      Refresh event is the update method, e.g.: $(selector).mCustomScrollbar("update");

      I don’t know how your ajax function work or which scrollbar options you’re using (or the plugin version) but the archive contains an ajax example:
      https://github.com/malihu/malihu-custom-scrollbar-plugin/blob/master/examples/ajax_example.html

      Maybe it helps(?)

      Reply
      • webbieram
        Posted on October 27, 2015 at 17:31 Permalink

        Hi Malihu,
        actually second time dom generating

        mCustomScrollbar _mCS_4 class and some times mCS_no_scrollbar classs too.
        like this.

        i written a global function for the scrollbar and calling it when ajax status success.

        Reply
  22. Joo
    Posted on October 20, 2015 at 06:03 Permalink

    Sorry, I’m really new to this.
    I’ve notice that you said, png file (buttons) should be on my directory. Does it mean that this should be in the same folder with the html file?

    Reply
    • malihu
      Posted on October 20, 2015 at 23:16 Permalink

      No problem 🙂
      It should be on the same folder with the jquery.mCustomScrollbar.css file.

      Reply
  23. Leonid
    Posted on October 19, 2015 at 17:33 Permalink

    Hi! Somebody can help me???! I have mCSB container, and when cursor located over this container – scrolling with mousewheel don’t work!!! This scroll work only when cursor located on scrollbar. What’s wrong??

    Reply
    • malihu
      Posted on October 19, 2015 at 22:00 Permalink

      Need some more info… in what kind of element do you apply the scrollbar? Are there other scripts/plugins on the same element?

      Reply
      • Leonid
        Posted on October 20, 2015 at 11:22 Permalink

        so, there are -list in mcsb_container. And exactly on this element my scrolling is not work.

        http://loginov.getphoto.dev1.msoft.su/personal/card/order/?without_reg=Y

        in form “Адрес доставки”. -> field (where default “Пермский край”)

        Reply
        • malihu
          Posted on October 20, 2015 at 23:30 Permalink

          Sorry but I cannot find where custom scrollbar is used…
          Which form are you referring to? What do I need to do to see the scrollbar in action?

          Reply
  24. Johnny
    Posted on October 19, 2015 at 15:55 Permalink

    Hi,

    Love your plugin and have used it several times.
    Now I need something different and I wanted to try and achieve it using this plugin.
    I have a horizontal scrolling div that I would like to scroll only when user scrolls vertically. I want to trigger x-scroll using only y-scroll.
    Is that possible using your plugin?
    Is it easy to implement it?
    If yes, could you show me a starting point?

    Thanks
    Johnny

    Reply
    • malihu
      Posted on October 19, 2015 at 16:22 Permalink

      Hi Johnny,

      I don’t think it’s possible, at least not without modifying plugin’s main script.
      When you say x-scroll, you mean content touch-swipe scrolling, trackpad scrolling or both?

      EDIT: Also, I don’t know how your page works but if we could do it, would this be user-friendly?

      Reply
      • Johnny
        Posted on October 19, 2015 at 16:59 Permalink

        Hi,

        Thank you for the prompt answer!
        When I say x-scroll I only mean mouse input using either scrolling or trackpad (good point thanks) I would like to keep touch-swipe functionality as is.

        Do you think it would be relatively easy for me to modify the code to achieve the above? (by giving me a starting point?)

        I was thinking of making an adapter for mouse wheel event and prevent default on the x-scroll and only use y-scroll .. or something like that.

        Thanks
        J

        Reply
        • malihu
          Posted on October 21, 2015 at 00:09 Permalink

          In jquery.mCustomScrollbar.js try changing line 1471 from:
          dlt=e.deltaX || e.deltaY || delta;
          to:
          dlt=e.deltaY;
          and see if it does what you need.

          Reply
  25. MrRobot
    Posted on October 19, 2015 at 03:02 Permalink

    Hello Malihu,
    I’m trying to implement JCCS and it works ok, the only thing is that if I have a container with the height of 100px and the images max-eight 100% the scripts rewrite the css at the end of the page load. this happen in firofox and chrome, in safari it works ok.

    Reply
    • malihu
      Posted on October 19, 2015 at 16:16 Permalink

      Is it a vertical or horizontal scrollbar? If the container height is fixed (100px) maybe you can set your images to max-eight: 100px instead of 100%?

      Can you send me link or test page/JSFiddle?

      Reply
      • MrRobot
        Posted on October 19, 2015 at 22:58 Permalink

        Sorry Malihu, It’s on my localhost.
        Gonna paste the code here, The contaniner is responsive so is using max-height 100% so the images. Works only with px or vh but it becomes static or acting weird.

        .GalleryWrapper { position:relative; width:100%; padding-bottom:30%; height:0; overflow:hidden; } .GalleryContent { position:absolute; overflow: inherit; background: #fff none repeat scroll 0% 0%; margin: 0px; height: 100%; box-sizing: border-box; display: block; float: left; } .GalleryImage{ max-height:100%; float: left;}
        <div class="GalleryWrapper"> <!-- content --> <div class="GalleryContent"> <img class="GalleryImage" src="/wp-includes/images/store/01.jpg"/> <img class="GalleryImage" src="/wp-includes/images/store/02.jpg"/> <img class="GalleryImage" src="/wp-includes/images/store/03.jpg"/> <img class="GalleryImage" src="/wp-includes/images/store/04.jpg"/> <img class="GalleryImage" src="/wp-includes/images/store/05.jpg"/> <img class="GalleryImage" src="/wp-includes/images/store/06.jpg"/> <img class="GalleryImage" src="/wp-includes/images/store/07.jpg"/> <img class="GalleryImage" src="/wp-includes/images/store/08.jpg"/> <img class="GalleryImage" src="/wp-includes/images/store/09.jpg"/> </div> </div>

        Reply
        • MrRobot
          Posted on October 19, 2015 at 23:00 Permalink

          and to note that with the code above in safari works like a charm.

          Reply
        • malihu
          Posted on October 20, 2015 at 23:13 Permalink

          I’m assuming you apply the scrollbar on .GalleryContent element(?)
          If yes, try giving it a width value, e.g. .GalleryContent{ width: 100%; }

          I’m also assuming you’ve enabled autoExpandHorizontalScroll option(?)

          Reply
  26. bendaoud
    Posted on October 16, 2015 at 17:46 Permalink

    hello, i have a problem with this plugin jquery.mCustomScrollbar.concat.min.js on firefox 40.0.3,

    the method mCustomScrollbar(“scrollTo”,”100px”)doesn’t work all the time , here is my code
    $("#areaPageView").mCustomScrollbar("scrollTo","500px");
    i add dinamicly content by scrolling down or up, i would like ,in case of scrolling down,
    to scroll before bottom after adding the ajax content on page, so user understand that there is more content to load, i used the alwaysTriggerOffsets:false to prevent multiples triggers

    i have the same probleme on 9.0.8112.16421,

    i hope i was clear, and thank you in advance for you answeer,

    M’Barek

    Reply
    • malihu
      Posted on October 16, 2015 at 20:17 Permalink

      Without seeing your ajax code I can’t really say why this happens but you need to make sure you call the scrollTo method after the new content is fully loaded (this includes newly added images etc.). Otherwise, the script will cancel scrollTo method while its updating the scrollbar to accommodate for the new content. I’m not sure this is the case for you. If it is, you might also use the scrollTo method’s timeout option to delay it.

      Reply
  27. webbieram
    Posted on October 16, 2015 at 12:40 Permalink

    Hi Malihu,
    First of all thx for your great plugin.

    But there is a small problem with the drag.
    Once i clicked on the drag from any point of view port i can drag and scroll the content. I want to stop scrolling once i focus out from the drag button. How can i do it? actually i m trying to fix it for horizontal scroll bar.

    Reply
    • malihu
      Posted on October 16, 2015 at 20:43 Permalink

      The scrollbar should be dragged when you click on it. What do you mean by “Once i clicked on the drag from any point of view port…”?

      Also, do you want to drag-scroll only when cursor is exactly over the scrollbar? This is not very user-friendly(?)

      Reply
  28. Flaviu
    Posted on October 15, 2015 at 15:06 Permalink

    Hi there,
    I want to use this for a grid but to work the same way your thumbnail scroll does .. and to have the arrows only for the horizontal scroll ( gallery browsing type ) .. I need to set the arrows somewhere bellow the th and lets say if I have 100 records the arrows should follow when I scroll vertically ..
    Can I achieve that with this plugin ? Thank you very much, I hope you can respond fast : )

    Reply
    • Flaviu
      Posted on October 15, 2015 at 15:15 Permalink

      Also I dont need the dragger .. only the arrows

      Reply
    • malihu
      Posted on October 15, 2015 at 15:42 Permalink

      Probably yes. It would require some special CSS (e.g. to hide the scrollbar, position the buttons etc.) and it also might require few callbacks and/or options set.

      If you can create and send me the HTML along with some visualization (e.g. few images) showing how exactly you want it to work, I could probably make it work for you.

      Reply
      • Flaviu
        Posted on October 15, 2015 at 15:58 Permalink

        Thanks for the quick response.
        I managed to hide the scroll bar .. the problem is that I want to set bigger arrows like 48×48 .. if I modify the container’s height I’m afraid it will prevent me from selecting the row ( selectable rows grid ) .. also can I modify the speed of the arrows on click ? Like in your thumbnail scroll .. click-25 .. click-50 .. something like that is what I’m looking for.

        Reply
        • Flaviu
          Posted on October 15, 2015 at 16:03 Permalink

          I managed to make the arrows follow the vertical scroll .. I’ve sent you a picture of how it looks so far.

          Reply
          • Flaviu
            Posted on October 15, 2015 at 16:06 Permalink

            So I really need to remove the dragger so it wont create any problems .. this is how I initialize the plugin:
            $(“.grid-selector”).mCustomScrollbar({
            axis:’x’,
            alwaysShowScrollbar: 0,
            scrollButtons:{ enable: true },
            mouseWheel:{ enable: false },
            autoDraggerLength:false,
            theme:”dark”
            });

      • Flaviu
        Posted on October 15, 2015 at 16:44 Permalink

        Did you get my email ?
        So what’s needed yet ..
        -increase scrolling for arrows (I see it’s 1px / click now )
        -remove dragger (hidden works but it overlaps the grid and I can select the row under it )
        -hide left arrow after page loads and hide right arrow when we reach the end with the scrolling
        Thank you : )

        Reply
        • malihu
          Posted on October 15, 2015 at 17:10 Permalink

          Yeap. Just replied 😉

          Reply
          • Flaviu
            Posted on October 16, 2015 at 09:46 Permalink

            Thanks a ton, that has been really helpful.
            Cheers : )

  29. Eve V
    Posted on October 15, 2015 at 06:51 Permalink

    Can I use this with a WordPress site I am working on? I have webkit scrollbars now, but they do not help in FireFox so if your plugin can be included in WP, I will try. Do I need to enqueue the jquery in functions.php, or can I just link it in the header?

    Reply
    • malihu
      Posted on October 15, 2015 at 15:31 Permalink

      Sure.

      The best way is to enqueue the files in your functions.php.

      Create a custom-scrollbar folder in your theme’s (or child-theme’s) directory and upload plugin files in it.

      Open your functions.php and insert:

      add_action('wp_enqueue_scripts', 'custom_scrollbar_files' ); function custom_scrollbar_files(){ // plugin css wp_enqueue_style('custom-scrollbar-styles', get_template_directory_uri().'/custom-scrollbar/jquery.mCustomScrollbar.css', '3.1.0'); // jquery wp_enqueue_script('jquery'); // plugin script wp_register_script('custom-scrollbar-script', get_template_directory_uri().'/custom-scrollbar/jquery.mCustomScrollbar.concat.min.js', array('jquery'), '3.1.0', 1); wp_enqueue_script('custom-scrollbar-script'); }

      For child-themes change:
      get_template_directory_uri()
      to:
      get_stylesheet_directory_uri()

      Then, you can initialize the scrollbar via HTML or javascript. For example, to add the scrollbar with javascript, you could insert something like the following script in your theme’s footer.php below wp_footer() function

      <script> (function($){ $(window).load(function(){ $(selector).mCustomScrollbar(); }); })(jQuery); </script>

      or you could add the above (without the script tags) inside a new .js file in custom-scrollbar folder and enqueue it by adding it in custom_scrollbar_files function in functions.php

      // plugin init script wp_register_script('custom-scrollbar-init-script', get_template_directory_uri().'/custom-scrollbar/your-filename.js', array('jquery', 'custom-scrollbar-script'), '3.1.0', 1); wp_enqueue_script('custom-scrollbar-init-script');

      Reply
      • Eve V
        Posted on October 16, 2015 at 18:19 Permalink

        Thank you so much for the detailed instructions!!
        I am going to do this soon, hope I won’t have to bug you for more help!!

        Much appreciated.

        Reply
      • Eve
        Posted on October 27, 2015 at 18:23 Permalink

        http://www.annweiner.com/sculpture/

        For a reason I can’t find, when this site opens in Safari the horizontal scrollbars for the long thumbnail divs do not appear. But if I resize the browser window they pop right in.

        Reply
        • malihu
          Posted on October 27, 2015 at 20:28 Permalink

          When you say Safari you mean the OSX/desktop or iOS/mobile version?

          Reply
          • Eve V
            Posted on October 28, 2015 at 18:11 Permalink

            desktop.
            I have the script in the footer like this:

            (function($){
            $(window).load(function(){
            $(“.heroText”).mCustomScrollbar();
            axis:”y”,
            scrollbarPosition: “outside”
            });
            })(jQuery);

            (function($){
            $(“.TNHolder “).mCustomScrollbar({
            axis:”x”,
            scrollbarPosition: “outside”
            });
            })(jQuery);

            seems I should be able to consolidate it, but when I try it breaks.

        • Eve
          Posted on October 28, 2015 at 18:13 Permalink

          The script tags were not copied into that code I pasted, but each function is wrapped in script tags, and that seems not quite efficient- however, without both it ceases to function properly.

          Reply
          • malihu
            Posted on October 28, 2015 at 21:39 Permalink

            To post code in comments you need to use the code tag (see info below the comment field).

            The first part of your code is not correct. It should be:

            $(".heroText").mCustomScrollbar({ axis:"y", scrollbarPosition: "outside" });

            Plugin options should be inside mCustomScrollbar function (like in the second part of your code).

          • Eve
            Posted on November 1, 2015 at 05:42 Permalink

            Thank you,
            I repaired that, but still Safari does not open the horizontal scrollbar on the .TNHolder divs until I resize the window. Works fine in other browsers. Odd.
            And the vertical one works just fine in Safari.
            This is the code:
            It doesn’t even use $(window).load

            (image heavy site)

            (function($){
            $(“.TNHolder “).mCustomScrollbar({
            axis:”x”,
            scrollbarPosition: “outside”
            });
            })(jQuery);

          • Eve
            Posted on November 1, 2015 at 05:47 Permalink

            <script> (function($){ $(window).load(function(){ $(".heroText").mCustomScrollbar({ axis:"y", scrollbarPosition: "outside" }); })(jQuery); </script> <script> (function($){ $(".TNHolder ").mCustomScrollbar({ axis:"x", scrollbarPosition: "outside" }); })(jQuery); </script>

            posted correctly here I hope

          • Eve
            Posted on November 1, 2015 at 17:03 Permalink

            Hey,
            I think I fixed it, it now works in Safari as well as elsewhere. I added the setWidth:false option and now it is fine. I think that div had a max width in the css, so that may have been the problem, anyway, it works and I want to thank you again for your great and very useful work and your attention to your public!

            Eve

          • Eve
            Posted on November 1, 2015 at 17:07 Permalink

            I spoke too soon, closed and re-opened Safari and re-tested and still no horizontal scrollbars on the thumbnail div! :>((

            I will try whatever you tell me.
            here is code:
            <script> (function($){ $(window).load(function(){ $(".heroText").mCustomScrollbar({ axis:"y", scrollbarPosition: "outside" }); })(jQuery); </script> <script> (function($){ $(".TNHolder ").mCustomScrollbar({ axis:"x", setWidth: false, scrollbarPosition: "outside" }); })(jQuery); </script>

            verticals are perfect!!

          • malihu
            Posted on November 1, 2015 at 17:46 Permalink

            Try calling both on window load and enable autoExpandHorizontalScroll option on the horizontal scrollbar:

            <script> (function($){ $(window).load(function(){ $(".heroText").mCustomScrollbar({ axis:"y", scrollbarPosition: "outside" }); $(".TNHolder ").mCustomScrollbar({ axis:"x", scrollbarPosition: "outside", advanced:{autoExpandHorizontalScroll:true} }); }); })(jQuery); </script>

  30. Jordan
    Posted on October 14, 2015 at 23:12 Permalink

    Hello, on beginning thanks for that great script! I was using it for the last year for showing images in my web portfolio and was happy with it. However the older version couldn’t offer scrolling via keyboard I decided to upgrade to the newest version. After some problems I finally run new script and almost everything is ok. Almost because I have two issues which I can’t manage. The first problem is themes… If I set for example the “rounded-dots” I can’t see the arrows on both ends – just dots – it is with all of them – I can see them in demo pages.

    The second issue is more important for me. In new script I can’t show image using scrolling when image width is bigger then DIV field. For example DIV is 900px width but image is 1000px. It is working on old script but not in new one. Maybe I have to add something in configuration but I don’t know what… I hope I explained clear enought. If no please look on the source code in:

    http://busiakiewicz.com/index.php?page=exteriors – there is old script and it is ok, while in this link:

    http://busiakiewicz.com/index1.php?page=exteriors there is new script and script is showing only 1 image. The problem is definitely the last image which is longer than DIV

    thanks in advance

    Reply
    • malihu
      Posted on October 14, 2015 at 23:38 Permalink

      Hello,

      To enable the buttons use the scrollButtons option parameter like this:
      scrollButtons:{ enable: true }
      and make sure you have mCSB_buttons.png on your directory.

      For the second issue I’ll need to investigate further but try setting autoExpandHorizontalScroll value to 2 (integer).

      So, make your script like this:

      $("#portfolio_image").mCustomScrollbar({ axis:"x", theme:"rounded-dots", advanced:{ autoExpandHorizontalScroll: 2 }, scrollButtons:{ enable: true } });

      Let me know if it works

      Reply
      • Jordan
        Posted on October 15, 2015 at 00:28 Permalink

        Thank You so much for that quick respond to my issue. It’s working like a charm! I spend good few hours on it trying to find solution and it was just a small thing…

        There is one more thing which I am thinking about and trying to do – is it possible to automatically activate keyboard scrolling (using arrows?) at this moment I have to “click” on the image first and than I can use arrows… The same with the mouse-wheel – it scrolls images only when the pointer is over the image.

        Thanks again!

        Reply
        • malihu
          Posted on October 15, 2015 at 02:03 Permalink

          Yes this is the standard behavior (it simulates exactly what browser’s default scrollbar does).

          You’ll need to add few lines of extra code to achieve those.

          For the mouse-wheel (check this example), you need something like:

          $("#another-element").on("mousewheel",function(e,delta){ e.preventDefault(); $("#portfolio_image .mCustomScrollBox").trigger("mousewheel",[delta]); });

          #another-element being the element to trigger the mouse-wheel when hovered.

          For the keyboard arrows, the following will work on any element with custom scrollbars (as it is):

          $(".mCustomScrollBox").on("mouseenter",function(){ $(this).attr("tabindex","0").focus(); }).on("mouseleave",function(){ $(this).blur(); });

          Just make sure you don’t break the user experience especially with the mouse-wheel functionality 🙂

          Reply
    • malihu
      Posted on October 15, 2015 at 00:05 Permalink

      Ok I checked your markup a bit further. Setting autoExpandHorizontalScroll to 2 (as suggested) will work.

      Another way is to set it to true (as you had it before) but you need to set your element’s CSS to white-space: nowrap;, e.g.:
      #portfolio_image{ overflow-x: auto; white-space: nowrap; }

      I’ve recently updated the autoExpandHorizontalScroll function (in version 3.1.0) to act exactly like browser’s default scrollbar on overflowed-x content. This means that according to your elements CSS rules you can set its value (in addition to true/false or 1/0) to 2 or 3 for more control on how elements are expanded horizontally (see option info).

      In some cases this might require a specific value (in your case 2), so you just got a bit unlucky there 🙂

      Good feedback though so thank you!

      Reply

Comments pages: 1 68 69 70 71 72 85

Post a comment

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

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

css.php