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
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).
HTML
Include jquery.mCustomScrollbar.css in the head tag your HTML document (more info)
<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
<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>
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 scrollbaraxis: "yx"
– vertical and horizontal scrollbars
scrollbarPosition: "string"
- Set the position of scrollbar in relation to content.
Available values:"inside"
,"outside"
.
SettingscrollbarPosition: "inside"
(default) makes scrollbar appear inside the element. SettingscrollbarPosition: "outside"
makes scrollbar appear outside the element. Note that setting the value to"outside"
requires your element (or parent elements) to have CSSposition: 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 to0
to disable.
autoDraggerLength: boolean
- Enable or disable auto-adjusting scrollbar dragger length in relation to scrolling amount (same bahavior with browser’s native scrollbar).
SetautoDraggerLength: false
when you want your scrollbar to (always) have a fixed size.
autoHideScrollbar: boolean
- Enable or disable auto-hiding the scrollbar when inactive.
SettingautoHideScrollbar: 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 visiblealwaysShowScrollbar: 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.
Setaxis: "y"
(default) for vertical oraxis: "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, setcontentTouchScroll: 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 totrue
, content will expand horizontally to accommodate any floated/inline-block elements.
Setting its value to2
(integer) forces the non scrollHeight/scrollWidth method. A value of3
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, setautoScrollOnFocus: 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 betrue
(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 isauto
which triggers the function only on"x"
and"yx"
axis (if needed).
The value should betrue
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, settingupdateOnSelectorChange: "ul li"
will update scrollbars each time list-items inside the element are changed.
Setting the value totrue
, will update scrollbars each time any element is changed.
To disable (default) set tofalse
.
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, settingonTotalScrollOffset: 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, settingonTotalScrollBackOffset: 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.
SetalwaysTriggerOffsets: 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.
Setlive: 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, setlive: "off"
and"on"
respectively.
You can also tell the script to disable live option after the first invocation by settinglive: "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.
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"
- e.g. element selector:
integer
- e.g. number of pixels:
100
- e.g. number of pixels:
[array]
- e.g. different y/x position:
[100,50]
- e.g. different y/x position:
object/function
- e.g. jQuery object:
$("#element-id")
- e.g. js object:
document.getelementbyid("element-id")
- e.g. function:
function(){ return 100; }
- e.g. jQuery object:
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
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);
destroy
Usage $(selector).mCustomScrollbar("destroy");
Calling destroy method will completely remove the custom scrollbar and return the element to its original state (demo).
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" });
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; }
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 startswhileScrolling
– triggers while scroll event is runningonScroll
– triggers when a scroll event completesonTotalScroll
– triggers when content has scrolled all the way to bottom or rightonTotalScrollBack
– 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).
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).
Additional callbacks:
onInit
onOverflowY
onOverflowX
onOverflowYNone
onOverflowXNone
onUpdate
onImageLoad
onSelectorChange
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 objectthis.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 percentagethis.mcs.leftPct
– content horizontal scrolling percentagethis.mcs.direction
– content’s scrolling direction (y or x)
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
- jQuery version 1.6.0 or higher
- Mouse-wheel support
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
Donating helps greatly in developing and updating free software and running this blog π
Hi there (again).
Is it possible to set a fixed height for the horizontal scrollbar (rail & dragger)?. LetΒ΄s say 150px for both?
IΒ΄ve been tweaking the values included in section 3 (HORIZONTAL SCROLLBAR x-axis) but it seems that those values are depending on some other values I cannot locate. IΒ΄m not using any theme so IΒ΄m asuming is the default (light) which (afaik) is not including any styling besides color overrides.
Could you please me point at the right direction?.
Thank you!
The first thing to do is set autoDraggerLength option parameter to false, e.g.:
$(selector).mCustomScrollbar({ autoDraggerLength: false });
and then change the CSS (line 170-180).
Hi, Well it’s great this plugin, but i have a question, How I can use the ‘mct.top’, to put a different color to that percentage of what remains to be seen ?, thanks
I can’t really understand what you’re trying to do. Can you explain a bit more? The percentage of what?
I’m struggling to understand the syntax for ‘live’ and ‘liveSelector’. I understand why they’re supposed to do, but I can’t figure out the exact syntax. Can you show an example? π
Sure.
live
is the basic option which sets live mode on/off.liveSelector
is an extra option which can be used to specify a different selector than the one called on mCustomScrollbar function.Examples:
1. Elements with class “myClass” will get custom scrollbar, now and in the future:
$(".myClass").mCustomScrollbar({ live:"on" });
Optionally, if/when live functionality is not needed anymore:
$(".myClass").mCustomScrollbar({ live:"off" });
2. Existing elements with class “myClass” and “myOtherClass” will get custom scrollbar. Elements with class “myOtherClass” will get custom scrollbar, now and in the future:
$(".myClass, .myOtherClass").mCustomScrollbar({ live:"on", liveSelector:".myOtherClass" });
Optionally, if/when live functionality is not needed anymore:
$(".myOtherClass").mCustomScrollbar({ live:"off" });
Hi dear,
Thank you for this plugin, it is very nice & cool but i have some problems to use it on safari. Mousewheel doesn’t works on Safari 5.1.7 for windows, i can only click on the arrow to scroll the content, you can see the problem with your demo’s page: http://manos.malihu.gr/repository/custom-scrollbar/demo/examples/scrollbar_themes_demo.html
I have an other problem on Safari 5.1.10 for Mac Os X – Mac Book PRO – Trackpad, the scrolling can get very jittery when i scroll down.
Can you help me to fix it?
Thank you in advance.
Last information i miss it: i use the version 3.1.11 of the plugin
I am worried about not seeing a response, the plugin does works on Safari?
No answer, too bad, i change plugin!
Hello,
The plugin works in Safari. Your issue about Safari version 5 has to do with the jquery mousewheel plugin.
You can try changing mousewheel plugin version and/or changing the mousewheel options this plugin provides. Specifically:
mouseWheel:{ scrollAmount }
,mouseWheel:{ deltaFactor }
andmouseWheel:{ normalizeDelta }
.The above might also make trackpad scrolling on Safari 5.1.10 smoother.
The following discussion on mousewheel plugin might also help:
https://github.com/jquery/jquery-mousewheel/issues/90
PS. I understand your frustration when dealing with an issue but please consider that the plugin is free and responding to comments takes time (and should not be taken for granted).
Hello. I’m not good with English, and I use a translator. Thank you so much for the best plugin for scrolling sites. And not think of a better guess. I have a question for you. I can not understand how to use your scroll to the events in scripts. For example I want to when scrolling down the page 300pks, I get a fixed menu navigation. If I use the scroll by default, then everything works fine. But with your scrolls, nothing happens.
What can be changed in the script? Here is an example script for the appearance of the menu:
$(document).ready(function(){ var $menu = $("#menu"); $(window).scroll(function(){ if ( $(this).scrollTop() > 100 && $menu.hasClass("default") ){ $menu.fadeOut('fast',function(){ $(this).removeClass("default") .addClass("fixed transbg") .fadeIn('fast'); }); } else if($(this).scrollTop() <= 100 && $menu.hasClass("fixed")) { $menu.fadeOut('fast',function(){ $(this).removeClass("fixed transbg") .addClass("default") .fadeIn('fast'); }); } });//scroll $menu.hover( function(){ if( $(this).hasClass('fixed') ){ $(this).removeClass('transbg'); } }, function(){ if( $(this).hasClass('fixed') ){ $(this).addClass('transbg'); } });//hover });//jQuery
Hello,
You’ll need to use your code inside plugin’s whileScrolling callback (instead of
$(window).scroll()
. For example:$(selector).mCustomScrollbar({ callbacks:{ whileScrolling:function(){ var pos=this.mcs.top,$menu=$("#menu"); if(pos<-300 && $menu.hasClass("default")){ /* show fixed menu code... */ }else{ if($menu.hasClass("fixed")){ /* hide fixed menu code... */ } } } } });
Did as you asked. Still does not work. Maybe error in the code?
Here it is:
$(document).ready(function(){ var $menu = $("#menu"); $(body).mCustomScrollbar({ callbacks:{ whileScrolling:function(){ var pos=this.mcs.top,$menu=$("#menu"); if(pos<-300 && $menu.hasClass("default")){ /* show fixed menu code... */ $menu.fadeOut('fast',function(){ $(this).removeClass("default") .addClass("fixed transbg") .fadeIn('fast'); }); }else{ if($menu.hasClass("fixed")){ /* hide fixed menu code... */ $menu.fadeOut('fast',function(){ $(this).removeClass("fixed transbg") .addClass("default") .fadeIn('fast'); }); } } } } }); $menu.hover( function(){ if( $(this).hasClass('fixed') ){ $(this).removeClass('transbg'); } }, function(){ if( $(this).hasClass('fixed') ){ $(this).addClass('transbg'); } });//hover });//jQuery
Oh I see…
Change callback conditions to:
if(pos<-300){ if($menu.hasClass("default")){ $menu.stop().fadeOut('fast',function(){ $(this).removeClass("default") .addClass("fixed transbg") .fadeIn('fast'); }); } }else{ if($menu.hasClass("fixed")){ $menu.stop().fadeOut('fast',function(){ $(this).removeClass("fixed transbg") .addClass("default") .fadeIn('fast'); }); } }
Also, is the following correct?
$(body).mCustomScrollbar({ ...
Cause body is not a variable defined anywhere(?). Maybe it should be:
$("body").mCustomScrollbar({ ...
Thank you very much, it worked. But then there was another little problem. Now scroll shows an arbitrary topic. You can do something so that was the subject of minimal-dark1?
theme: "minimal-dark1", scrollInertia: 810 autoHideScrollbar: three
How does this tie to the code?
These are all option parameters (same as callbacks):
$("body").mCustomScrollbar({ theme: "minimal-dark", scrollInertia: 810, callbacks:{ /* callbacks code */ } });
Thank you so much! Now everything works fine. Good luck to you!
hello , we are using a div that get get on ajax call, then how we do have to use this custome scroll js after updating the inner html as on load this div is display none default.
Thanks
Is the div element generated on ajax call or the element exists in the HTML and its content changes by ajax? In the first case you just call
mCustomScrollbar
after your element is generated. In the second case you use$(selector).mCustomScrollbar("update");
after you content has changed.Note that when plugin has initialized, the actual content resides inside .mCSB_container div, so to modify it, you can do something like:
$("#my-element-id .mCSB_container").html("content"); $("#my-element-id").mCustomScrollbar("update");
The plugin archive contains examples of ajax and initially hidden elements.
Thanks a lot, it’s working… π
You’re welcome. I edited my answer above as I made an error and it wasn’t very clear.
dude, you’re awesome, especially taking so much time to help people using your plugin, with helpful and prompt replies.
great work, man
Thanks! I try to make time each day for replies, support etc.
First, thanks for this plugin.
I’m trying to use the “dark” theme but it doesn’t show anywhere inside the ul, when I inspect in the browser I have to add a width, position: absolute and a background-color and it shows in the left side. Can you help me? Thanks a lot.
Update:
The scroll bar shows when I hover the right border. Is this normal? or it should show always?
No it should always be visible. Can’t really say what might be wrong but it sounds it’s something with your CSS. Note that elements with vertical scrollbar need a height/max-height value and elements with horizontal scrollbar need a width/max-width.
It is not working for ie9 please help me sort this out.
I need more info on this to be able to help (your page link, testing environment etc.).
The plugin is tested and works as expected in IE9 (version 9.0.8112.16421) under Windows Vista (service pack 2).
wondows7 professional and ie9
pelase dowload from link.
https://www.dropbox.com/s/kiy1nc4nar3674e/zzzzz.html?dl=0
Your element (#article) needs a height (or max-height) value.
It worked,Thank you!!!
1. What is stupid code?
_delete: function (p) { try { delete p } catch (e) { p=null } }
The right code is:
_delete: function (context, member) { try { delete context[member] } catch (e) { context[member] = undefined } }
And then use:
functions._delete(value, 'member')
2. The global last parameter: undefined does not used anywhere!
Instead it:
if (typeof value != "undefined")
3. The jQuery has static method $.isNumeric(value)!
What is purpose to use functions._isNumeric(value) that implement same code as jQuery $.isNumeric?
4. Instead code:
if (typeof value == 'function')
Use code
if ($.isFunction(val))
5. Why did not obfuscated the names of all private members: functions._XXX? The minified code is very redundant!
Thanks for the feedback!
1. What would be the benefit of
delete c[m]
instead ofdelete c.m
in the script? Aren’t the same thing? Your suggested function would require more code (to be passed as function parameters/vars).2. undefined parameter will be removed in next version.
3. $.isNumeric was added in jQuery version 1.7 but the plugin still supports 1.6.0.
4. I cannot see a benefit of using
$.isFunction
vstypeof
in the script ($.isFunction is also a bit slower). Can you elaborate more on this?5. I wanted to make function names clear (as to what they do). Not sure how much difference would it make though.
1. In Your original code used
var functions={ // PlugIn private methods ... /* deletes a property (avoiding the exception thrown by IE) */ _delete:function(p){ try{delete p;}catch(e){p=null;} }, /* -------------------- */ // PlugIn private methods ... } // Does not delete liveTimers[selector] functions._delete.call(null,liveTimers[selector]); // Does not delete this.mcs functions._delete.call(null,this.mcs); // Does not delete $this[0]._focusTimeout functions._delete.call(null,$this[0]._focusTimeout); // Does not delete mCSB_container[0].onCompleteTimeout functions._delete.call(null,mCSB_container[0].onCompleteTimeout); // Does not delete mCSB_container[0].autoUpdate functions._delete.call(null,mCSB_container[0].autoUpdate); // Does not delete d.sequential.step functions._delete.call(null,d.sequential.step);
2 – 5. The size of minified code will be lower
3. It’s not actual now (jQuery version 1.6.0)
Thanks! I’ll update the function in the next version and try to make the minified code size less.
3. The plugin does work with 1.6.0. Changing
_isNumeric
to$.isNumeric
doesn’t.Hi,
Thanks for share this great thing.
I’m using this plugin in my site. Its working fine but i need your help to fix a bug.
I have a list of few videos in scroller. when someone click on video list item the scroller should scroll to current clicked item
you can check here http://faisalabad.lokpunjab.org/#video_player_wrapper
I try to do this with this code
jQuery('.realted_mutlimedia .video_list').click(function(){ var scroll = jQuery(this).index()*list_height; jQuery('.realted_mutlimedia').mCustomScrollbar("scrollTo",scroll); });
It will be good if you reply me on my mail address.
Thank alot
Hi,
Thanks very much for the hard work you put into this.
I’m looking to use this plugin in my SharePoint portal site.
The thing in SharePoint is that any content you create is hosted inside SharePoint components (like Webparts) and you cannot really control this. Meaning, I cannot wrap a webpart with my own div that has your class.
Can I set the plugin to generally work everywhere? To make it work where any scroll bar appears?
Thanks!
The plugin will work on any jquery selector as long as the element has the proper CSS properties set (e.g. height, max-height, overflow etc.) and it’s able to generate the necessary markup.
Thanks a lot again for such a professional plugin.
Hi there.
First of all thanks for sharing this resource man!.
Is there a way to set the scrollbar container to a fixed size instead of always having the same size the overflowed:auto/hidden parent has? The goal would be to have a very lenghtly container (scrolling area) with a much more small dragger and dragger container.
IΒ΄ve tried using the autoDraggerLength: true method but this only changes the dragger portion of the component which causes the scrollbar container to look too long and out of proportion compared to the dragger.
Thank you!.
All scrollbar styling is done via CSS. Specifically, the vertical scrollbar is defined on line 65 of jquery.mCustomScrollbar.css. For example, to set a fixed height you can do:
.mCSB_scrollTools{ position: absolute; width: 16px; height: 200px; left: auto; top: 0; right: 0; }
You can set its size however you like, e.g.:
.mCSB_scrollTools{ position: absolute; width: 16px; height: auto; left: auto; top: 0; right: 0; bottom: 0; margin: 50px 0; }
or even:
.mCSB_scrollTools{ position: absolute; width: 16px; height: 50%; left: auto; top: 25%; right: 0; }
Thanks for the quick reply man.
I ended up by changing the values from the selector at line 156 instead which seems to control the actual width of the horizontal scroll container. IΒ΄m leaving it here for the record just in case someoneΒ΄s looking for the same thing:
.mCSB_scrollTools.mCSB_scrollTools_horizontal{ /*width: auto; <---- Original Value*/ width:500px; /*New value */ height: 16px; top: auto; right: 0; bottom: 0; left: 0; }
It is actually pretty awesome that you left styling dimensions out of the script. I like this modular approach a lot.
Thanks again!.
Hi is it possible to have something like a ‘delta’ scrolling? According to the docs, I can define the position in pixels to scroll to, but can I say “scroll x px further down” from the current position? Thx
Yes you can (docs need updating sorry). You can do it like this:
$(selector).mCustomScrollbar("scrollTo","-=100");
or:
$(selector).mCustomScrollbar("scrollTo","+=100");
And for position defined in a variable:
var to=100; $(selector).mCustomScrollbar("scrollTo","-="+to);
It’s very important, I agree with you upgrade, there are many tearing your hair out with this. Thank you for this wonderful plugin
Hi! I do love your scrollbar.
But I have some problems with
axis:”x”
in Safari.
in html I have this:
And
$(document).ready(function() {
$(‘.news’).mCustomScrollbar({
scrollInertia:100,
autoDraggerLength: false,
axis:”x”});
});
In Safary I dont see neither images in tags nor Scrollbar
Could you help me please?
http://www.toguchi.ru/test.html
Hi,
I think you need to give your table a width value in pixels. Either this or maybe call plugin function on window load (instead document ready):
$(window).load(function() { ... });
how can I add this to dynamically generated content.
I’ve added mCustomScrollbar to a div inside of which, I’m changing the content using .html().
The scroll-bar shows up in the old content if it is created statically but disappears in the newly generated one.
What can I do?
New content must be added inside .mCSB_container div and not directly inside your element, e.g.
$("#element-id .mCSB_container").html(...);
Hi there! I love your script, it’s very well done and smooth as silk.
I’m having an issue with the horizontal scroll and the magic mouse/touchpad. When I swipe left, the page scrolls right, and vice versa. The functionality works correctly using the scrollbar, keyboard, and mouse wheel. Only the touchpad seems to be behaving backwards.
Here’s my options for clarification:
$($mapWindow).addClass('mCustomScrollbar fluid').mCustomScrollbar({ axis: "x", theme: "dark", mouseWheel: { invert: true }, mouseWheel: { axis: "x" }, keyboard: { enable: true } });
Any suggestions to fix the touchpad inversion problem?
Hi,
You have
mouseWheel: { invert: true },
which inverts mouse-wheel scrolling direction. Normally it should be false (or removed). Did you try testing this option or?I did, and unfortunately it had no effect over horizontal swiping.
Here’s a URL to see it: http://www.wellspringstones.com/cartography/wellness
Well I can’t really say why this happens (I don’t have a mac/magic mouse to test it). There’s no known issue of this behavior although I don’t know if magic mouse works this way by default (does it behave the same when using browser’s native horizontal scrollbar?).
I tested your page on my iPad and it works correctly. I thought magic mouse used the mouse-wheel event/values but since the
invert
option has no effect, seems it doesn’t.It probably uses the touch event(?) which does work correctly on iPad, Android etc. but it’s probably inverted by the OS for mouse. I’m just guessing here but maybe there’s an option for magic mouse to invert touch-scrolling?
Just for clarification: Magic Mouse = Touch Pad. It’s the same functionality.
You are correct, but I currently have that disabled. Apple calls it “natural scrolling” but it’s the reverse of how we’ve all learned to use a mouse/touchpad over the years.
I just “enabled” the natural scroll on my OS X settings and the scroll behaves the correct way. It looks like the logic just needs to be flipped for touchpads?
Unfortunately there’s no way to differentiate between mouse and touchpad with javascript.
Is there a way to get this to work with an iframe targeting pages on the same server?
See iframe_example.html in plugin archive (online demo: http://manos.malihu.gr/repository/custom-scrollbar/demo/examples/iframe_example.html)
I found the iframe example page you have on github, however it is not reacting at all the same way your example page is for some reason. It loads the external page and then vanishes. You can see what I mean here – http://leepresson.com/slang.php
Your #iframe-container needs a height value (e.g.
height: 300px;
).Ah, the example didn’t have a height listed in the CSS code so I did not put it for some reason. It works but not entirely. It stops halfway down the page embedded in the iframe for some reason.
If I increase the height of the iframe, more is visible but that seems like a bad fix.
No, increasing iframe height is exactly what you need to do, since your iframe’s content is about 1400px and your iframe height is just 700px.
The custom scrollbar scrolls the entire iframe (1400px) within its height (300px). This is the only way js scrollbars work as they cannot access or modify iframe contents (iframes are different documents).
jQuery custom content scroller is very very slow in safari browser. can u give me the solution?
I need more info about the OS, device, browser version and what kind of content is scrolled.
There’s no known issue for Safari but performance depends on many things like OS, browser, hardware and content. Do you see the same performance on the demo pages? Can you send me a link?
Trying to use the JS in a responsive layout and an x-axis overflow situation.
The container overflowing fills the horizontal viewport on mobile devices, and the horizontal scroll works wonderfully.
However, trying to scroll the whole containing page vertically on the device doesn’t work if the touch event starts in the overflow element.
Is there a way of allowing normal vertical, whole page scroll behaviour if a user starts a vertical scroll by touching the screen on a horizontally overflowed element?
As a result, the user can scroll down and into the x-axis overflowed element, but can’t vertically scroll back out…
In latest version (3.0.5) you should be able to scroll the page while touch-swiping vertically a horizontal scrollbar (at least on iOS). Can you send me your page link?
Hi Malihu,
The bug is on Android 4.3, Chrome 39 and your latest 3.0.5 for definite.
On the same Android biuld, Firefox works fine.
So might be Chrome / Android+Webkit specific?
Can’t provide a link sadly as it’s a commercially sensitive build.
Will try on iOS.
I’ll check Chrome on Android and see if I can fix it on the next version. Thanks for the feedback π
I can confirm this issue, I was having the same problem in Chrome on Android. Other than that, script is incredible.
This is fixed in latest version (3.0.7)
Thanks for the feedback!
The ‘Configuration’ section on your website with the class=”articles” has a css property of margin-right for devices larger that 1024px:
@media only screen and (min-width: 1024px)
.articles {
margin-right: 380px;
}
on line 8 in ‘style.css’.
Removing that gives a much better viewing and reading experience! π Especially not having to scroll horizontally to read the entire description, and then to scroll back over to the start again.
Thank you for an excellent plugin. Works great.
The
margin-right: 380px;
rule is for positioning website’s sidebar. I’m still working on a better solution though. Thanks for the feedback.Hello ! We’ve made a funny website for a french pop-band with your excellent plugin on two of our page.
In this page http://andreasetnicolas.com/goodies.php at the bottom, we have a scrollbar with the wallpaper section. But I would to have the arrows and they don’t appear… do you have an idea of what goes wrong ?
In the medias.php page, we use the same configuration and its work 0____o
Thanks for the help !!
In your style.css on line 1109 you have:
.choix_wallp a{ ... }
. This affects all anchor tags inside .choix_wallp, including plugin’s anchor buttons (which become hidden as they get floated left).Just change the CSS selector to:
.choix_wallp li a{ ... }
so you can apply the style you want only on anchors inside list-items πOh yeeah ! It works, that was my fault >___<
Thanks for the speed of answer and for the time you took on my issue π
Hello,
First, thank you so much for your hard work on this! I have it on my site, implementation was smooth and it is working amazingly.
One thing I want to do is have the scroll bar appear to the left of the content, rather than the right as it is by default. Would it be possible to do this and if so, how?
Thanks in advance!
Guy
If you want general right-to-left direction you simply add
dir="rtl"
to your HTML/element(s).To just place the scrollbar on left, edit jquery.mCustomScrollbar.css. For the default scrollbar, change line 71 from:
right: 0;
to:right: auto;
and line 54 from:margin-right: 30px;
to:margin-right: 0; margin-left: 30px;
.You can of course overwrite these rules in another CSS, for example:
.your-class .mCSB_scrollTools{ right: auto; } .your-class .mCSB_inside > .mCSB_container{ margin-right: 0; margin-left: 30px; }
In general, the position and appearance of the scrollbar is done in jquery.mCustomScrollbar.css (see section 2 “VERTICAL SCROLLBAR” in CSS).
Hello!
Pretty new to this and I’m stuck!
So I am using the “dark” theme. I have two custom content scrollers set up right next to each other (similar to how it looks like your page that shows all of your themes.) I want both content scroller’s to be ‘dark” themed. However the second one looks as though all the styles have been taken off of it and just has the basic bar- not the “dark” bar.
I assume it must have something to do with the styling and maybe an ID?
Can’t really say why this happens as I don’t know your html/js but if you have 2 elements, each one with a unique id, you can do:
$("#id-1,#id-2").mCustomScrollbar({ theme:"dark" });
If your elements share the same class, you can do:
$(".class-name").mCustomScrollbar({ theme:"dark" });
Hi –
I have a simple email form that sits inside of a custom scrollbar window. I would like to redirect the user to a thank you page again another custom scrollbar window once they click the submit button. I have tried Send However it does not pick up the thank you custom scrollbar window.
Also how do I get the script to load the a specific custom scrollbar window when the page loads for the first time. At the moment it loads to a empty page and the custom scrollbar window only appears when the user clicks on a link.
This is the code I tried:
<button class="contact-email-submit" type="submit" onclick="location.hash = '#contact-thank-you';">Send</button>
Hi, I have a question, still related with Bootstrap dropdown issue. So I made a dropdown with custom scroll implemented on int. And then I made another DIV element to trigger that particular dropdown with a scrollTo event. If you see the attach jsfiddle script, Trigger 2 supposed to trigger the dropdown, while Trigger 1 supposed to trigger the dropdown with 100px scrolled down. But Trigger 1 doesn’t seems to work well. Sometimes it works, but some other times it doesn’t work (and mostly it doesn’t work).
Are there anything wrong with my script? Thanks.
Here is the link to the issue http://jsfiddle.net/u9pxth1f/
Thanks.
I had just solved my problem by calling .mCustomScrollbar(“update”) before working on .mCustomScrollbar(“scrollTo”) function.
Hi,
I have a slider and when I try to slide it – the whole page scrolled instead. Is there any solution for this issue? Especially on mobile devices (touch screen).
Thx.
You can see it here http://radio.micromir.com.ua/
You slider does slide horizontally but performance seems slow. You can try disabling updateOnImageLoad option and see if it gets better, e.g.:
$(selector).mCustomScrollbar({ advanced:{ updateOnImageLoad: false } });
Thx for your reply.
Your comment slightly improve performance. But you probably do not understand the problem. On the desktop, everything looks fine, but on mobile devices it is impossible slider slides vertically – when you try to do it freezes. Unplug your script and the slider is working correctly.
Can you try disabling both updateOnImageLoad and updateOnContentResize and see if it doesn’t freeze? If you can change it on your live site I’d be able to check it too (on http://radio.micromir.com.ua/ updateOnImageLoad is still enabled).
Disabling updateOnContentResize leads to turning off the scrollbar at all.
I made these changes on the live site so you can see them
Ok just re-enable updateOnContentResize
Re-enabled. But slider still does not work =(
Well it seems there’s some conflict between the scrollbar and some other script (slider or some other?) on touch. Maybe the slider does not allow touch event bubbling(?) but I can’t be sure. If you disable the sliders maybe we could see if there’s some conflict among these scripts.
Hi,
i’m using your plugin on this website
http://www.unioneimpreseitaliane.it/web
if you click on the links on the left, ths scrollto id works fine
however, i would like the scrolling to stop some pixels before the id so that there is more space between the container and the title of the box
i tried with the offset, but i’m not sure how and where to add it
this is my code:
<script> $(function(){ $(window).load(function(){ $("#main").mCustomScrollbar({ axis:"x", horizontalScroll:true, scrollInertia:1100, advanced:{ autoExpandHorizontalScroll:false }, /*, callbacks:{ onScroll:function() { alert("scrolled..."); } }, scrollButtons:{ enable:true }*/ }); /* Navigation */ $(".menu_sidebar a").click(function(){ axis:"x"; var myid= $(this).attr("href"); $(".menu_sidebar a").removeClass('selected'); $(this).addClass('selected'); $("#main").mCustomScrollbar("scrollTo","" + myid + ""); }); }); })(jQuery); </script>
thanks!
Give your target elements (e.g. #media, #servizi, #eventi etc.) a negative left margin that will act as offset. For example:
#media, #servizi, #eventi{ margin-left: -40px; }
Because your target elements are not positioned equally, you might need to adjust each one separately, e.g.:
#media{ margin-left: -40px; } #eventi{ margin-left: -40px; padding-left: 40px; } /* etc. */
Hi.
Confirm this issue – http://manos.malihu.gr/jquery-custom-content-scroller/comment-page-54/#comment-18096
Let’s say i have a sidebar with navigation, i’m using jquery’s
slideToggle()
for the accordion-like menu. Assume active link is on top of the page and expanded (with child items). Then i scroll down to the bottom of the nav and click on the last item which also has child items. If height of the second expanded menu item is bigger than the first one, the whole navigation jumps. I think it’s something related to live updating of the scroll bar position. Pretty annoying issue, plugin works perfectly everywhere, except this case πI’ve tried to disable it on nav item click and re-enable on slideUp() complete, it works, but now it jumps in another way π
Could you please take a look at this issue?
Thanks
Hi,
I’d need to see the issue online but maybe you could disable auto-updating (
advanced:{ updateOnContentResize: false }
) and call the update method manually after slideToggle?Hi there.
Thanks for a quick reply.
Unfortunately i’ve tested this solution before, it does work, but not as smooth as expected.
I’ve created a demo page where you can see the issue. Just scroll down at the very bottom and click “CLICK ME” menu item, you’ll see how navigation shrinks. This happens only if “CLICK ME” content is higher than “ACTIVE” menu item content.
You can also download these demo files if you want to play with the code.
This is a very powerful plugin, but unfortunately this issue makes it almost useless for fixed navigation from the UI point of view π
Anyway, i’d love to make a donation for your great support and great job you did with this plugin.
Thanks!
Hey,
I saw what you mean and I did some tests with the files you posted. I’ll send you the feedback via email π
I have the same problem :/ did you find a solution?
Yes. It depends on your markup/layout/script but the solution is to use plugin’s whileScrolling callback to stop and update the scrollbar.
Example:
var clicked=0; $(selector).mCustomScrollbar({ callbacks:{ whileScrolling:function(){ if(this.mcs.topPct===100){ $(selector).mCustomScrollbar("stop"); }else{ if(clicked===1){ $(selector).mCustomScrollbar("update"); } } } } }); /* later on... */ $(element).on("click", function(e){ clicked=1; $(other_element).slideToggle(400, function(){ clicked=0; }); });
Sorry, this is a correct link to the online demo.
Hi there Malihu,
I’m using bootstrap 3.20 + latest Silvio Moreto’s bootstrap-select plugin + your plugin and I’m having a problem with dropdowns. Namely, whenever I click on scrollbar or it’s buttons dropdown closes. How can I prevent this from happening. Thanx in advance.
here’s my config:
$(‘ul.selectpicker’).mCustomScrollbar({
theme:”inset-dark”,
contentTouchScroll: true,
scrollButtons:{
enable:true
}
});
Hello,
In order for this to work properly, you’ll need to add the following code after your mCustomScrollbar function call:
$(".dropdown-menu, html").on("mouseup pointerup",function(e){ $(".dropdown-menu .mCSB_scrollTools").removeClass("mCSB_scrollTools_onDrag"); }).on("click",function(e){ if($(e.target).parents(".mCSB_scrollTools").length || $(".dropdown-menu .mCSB_scrollTools").hasClass("mCSB_scrollTools_onDrag")){ e.stopPropagation(); } });
It’s a tiny “hack” to prevent closing the dropdowns when dragging the scrollbar π
Thanx a lot! It works! π yay!