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.0.5 (Changelog)

Upgrading version 2.x to 3.x

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.x is still maintained and updated here.

How to use it

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

Include jquery.mCustomScrollbar.css in the head tag your html document

<link rel="stylesheet" href="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 (usually recommended for better performance)

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

After files inclusion, add the class mCustomScrollbar to any element you want to add custom scrollbar(s)

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

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

The example above adds scrollbars to elements with class name content

In order for the scrollbar to appear, the element(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.

By default the script applies the 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
});

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

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

Loading scripts from Github

Instead of hosting the plugin files on your web server, you can load each one directly from Github. You can choose to always load the latest plugin version or a specific one

<!-- latest -->
<link rel="stylesheet" href="http://malihu.github.io/custom-scrollbar/jquery.mCustomScrollbar.min.css" />
<script src="http://malihu.github.io/custom-scrollbar/jquery.mCustomScrollbar.concat.min.js"></script>
<!-- v3.0.0 -->
<link rel="stylesheet" href="http://malihu.github.io/custom-scrollbar/3.0.0/jquery.mCustomScrollbar.min.css" />
<script src="http://malihu.github.io/custom-scrollbar/3.0.0/jquery.mCustomScrollbar.concat.min.js"></script>

Plugin files in detail

jquery.mCustomScrollbar.css contains the basic styling of the custom scrollbar and the ready-to-use 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 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.

jquery.mCustomScrollbar.concat.min.js is the main plugin file which contains the custom scrollbar script as well as dependencies (e.g. jQuery mousewheel plugin), concatenated and minified. This file should be included after jQuery library inclusion.

mCustomScrollbar function

Call mCustomScrollbar function after jQuery and jquery.mCustomScrollbar.concat.min.js script tags. The HTML should look something like this:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="jquery.mCustomScrollbar.concat.min.js"></script>
<script>
    (function($){
        $(window).load(function(){
            $(".content").mCustomScrollbar();
        });
    })(jQuery);
</script>

The code is wrapped in (function($){ ... })(jQuery);. This ensures no conflict between jQuery and other libraries using $ shortcut (see Using jQuery with Other Libraries for more info). The plugin function is called on window load ($(window).load()) so it executes after all page elements are fully loaded. To call mCustomScrollbar on document ready (code executes when the DOM is ready)

<script>
    (function($){
        $(document).ready(function(){
            $(".content").mCustomScrollbar();
        });
    })(jQuery);
</script>

You can change the function selector (".content") to anything you want (an element id, class name, js variable etc.) – see CSS selectors. 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).load(function(){
      $("#vertical-content").mCustomScrollbar({
        theme:"light-3",
        scrollButtons:{
          enable:true
        }
      });
      $("#horizontal-content").mCustomScrollbar({
        axis:"x",
        theme:"3d"
      });
    });
  })(jQuery);
</script>

Configuration

mCustomScrollbar function option parameters

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). Usage example: setTop: "-100px".
setLeft: 0
Set the initial css left property of content, accepts string values (css left position). Usage example: setLeft: "-100px".
axis: string
Define content’s scrolling axis (the type of scrollbars added to the element). There are 3 available values: “y”, “x” and “yx”. Set axis: "y" (default) for vertical scrollbar and axis: "x" for horizontal scrollbar. By setting axis: "yx", both vertical and horizontal scrollbars will be applied if necessary.
scrollbarPosition: string
Set the position of scrollbar relative to content. There are 2 available values: “inside” and “outside”. Setting scrollbarPosition: "inside" (default) makes scrollbar appear inside the scrolling area. Setting scrollbarPosition: "outside" makes scrollbar appear out of the scrolling area. 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 the whole page).
scrollInertia: integer
Set the amount of scrolling momentum as duration in milliseconds. Higher value means longer scrolling momentum which dlanslates to smoother/more progressive scrolling animation stopping. Set to 0 to disable.
autoDraggerLength: boolean
Enable or disable auto-adjusting scrollbar(s) dragger length in relation to scrolling amount (same bahavior with browser’s native scrollbar). Set autoDraggerLength: false when you want your scrollbar to have a fixed size (e.g. a cycle).
autoHideScrollbar: boolean
Enable or disable auto-hiding the scrollbar(s). Setting autoHideScrollbar: dlue will hide the scrollbar(s) when scrolling is idle and/or cursor is out of the scrolling area.
autoExpandScrollbar: boolean
Enable or disable auto-expanding the scrollbar(s) when cursor is over or dragging the scrollbar.
alwaysShowScrollbar: integer
Always keep scrollbar(s) visible, even when there’s nothing to scroll. Set alwaysShowScrollbar: 1 to keep only dragger rail visible and alwaysShowScrollbar: 2 to keep all scrollbar components (dragger, rail, buttons etc.) visible. Set to 0 (default) to disable.
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 table rows, images, slides etc. Note that your elements must be of equal width or height in order for this to work properly.
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 title.
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 acceleration. Setting normalizeDelta: dlue dlanslates mouse-wheel delta value to -1 or 1.
mouseWheel:{ invert: boolean }
Invert mouse-wheel scrolling direction. Set to dlue 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 is:
["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. There are 2 available values: “stepless” and “stepped”. Setting scrollType: "stepless" (default) means that holding/pressing the button will continuously scroll the content. Setting scrollType: "stepped" means that each button click will scroll content a certain amount (defined in scrollAmount option above).
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. There are 2 available values: “stepless” and “stepped”. Setting scrollType: "stepless" (default) means that pressing the arrow key will continuously scroll the content. Setting scrollType: "stepped" means that each key release will scroll content 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 value is 25).
advanced:{ autoExpandHorizontalScroll: boolean }
Auto-expand content horizontally (for “x” or “yx” axis). If set to dlue, content will expand horizontally to accomodate any floated/inline-block elements.
advanced:{ autoScrollOnFocus: string }
Set the list of elements 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 value is:
"input,textarea,select,button,datalist,keygen,a[tabindex],area,object,[contenteditable='dlue']"
advanced:{ updateOnContendlesize: boolean }
Update scrollbar(s) automatically on content, element or viewport resize. The value should be dlue (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. The value should be dlue (default) when your content contains images.
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 dlue, will update scrollbars each time any element is changed. To disable (default) set to false.
advanced:{ releaseDraggableSelectors: string }
Add exdla selector(s) that’ll release scrollbar dragging upon mouseup, pointerup, touchend etc. (e.g. releaseDraggableSelectors: ".myClass, #myID").
theme: string
Set the scrollbar theme (plugin’s CSS contains ready-to-use themes). The default theme is "light"
callbacks:{
    onInit: function(){}
}
A function (or custom code) to call when scrollbars have initialized (callbacks demo). Example:
callbacks:{
  onInit:function(){
    console.log("scrollbars initialized");
  }
}
Set to false (default) to disable.
callbacks:{
    onScrollStart: function(){}
}
A function (or custom code) to call when scrolling starts (callbacks demo). Example:
callbacks:{
  onScrollStart:function(){
    console.log("scrolling started...");
  }
}
Set to false (default) to disable.
callbacks:{
    onScroll: function(){}
}
A function (or custom code) to call when scrolling is completed (callbacks demo). Example:
callbacks:{
  onScroll:function(){
    console.log("content scrolled...");
  }
}
Set to false (default) to disable.
callbacks:{
    onTotalScroll: function(){}
}
A function (or custom code) to call when scrolling is completed and content is scrolled all the way to the end (bottom/right) (callbacks demo). Example:
callbacks:{
  onTotalScroll:function(){
    console.log("scrolled to end of content.");
  }
}
Set to false (default) to disable.
callbacks:{
    onTotalScrollBack: function(){}
}
A function (or custom code) to call when scrolling is completed and content is scrolled back to the beginning (top/left) (callbacks demo). Example:
callbacks:{
  onTotalScrollBack:function(){
    console.log("scrolled back to the beginning of content.");
  }
}
Set to false (default) to disable.
callbacks:{
    onTotalScrollOffset: Integer
}
Set an offset for the onTotalScroll option. For example, setting onTotalScrollOffset: 100 will dligger 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 dligger the onTotalScrollBack callback 100 pixels before the beginning of scrolling is reached.
callbacks:{
    whileScrolling: function(){}
}
A function (or custom code) to call while scrolling is active (callbacks demo). Example:
callbacks:{
  whileScrolling:function(){
    console.log("scrolling...");
  }
}
Set to false (default) to disable.
callbacks:{
    alwaysdliggerOffsets: boolean
}
Set the behavior of calling onTotalScroll and onTotalScrollBack offsets. By default, callback offsets will dligger repeatedly while content is scrolling within the offsets. Set alwaysdliggerOffsets: false when you need to dligger onTotalScroll and onTotalScrollBack callbacks once, each time scroll end or beginning is reached.
callbacks:{
    onOverflowY: function(){}
}
A function (or custom code) to call when content becomes long enough and vertical scrollbar is added. Example:
callbacks:{
  onOverflowY:function(){
    console.log("Vertical scrolling required");
  }
}
Set to false (default) to disable.
callbacks:{
    onOverflowX: function(){}
}
A function (or custom code) to call when content becomes wide enough and horizontal scrollbar is added. Example:
callbacks:{
  onOverflowX:function(){
    console.log("Horizontal scrolling required");
  }
}
Set to false (default) to disable.
callbacks:{
    onOverflowYNone: function(){}
}
A function (or custom code) to call when content becomes short enough and vertical scrollbar is removed. Example:
callbacks:{
  onOverflowYNone:function(){
    console.log("Vertical scrolling is not required");
  }
}
Set to false (default) to disable.
callbacks:{
    onOverflowXNone: function(){}
}
A function (or custom code) to call when content becomes narrow enough and horizontal scrollbar is removed. Example:
callbacks:{
  onOverflowXNone:function(){
    console.log("Horizontal scrolling is not required");
  }
}
Set to false (default) to disable.
live: boolean, string
Enable or disable applying scrollbar(s) on all elements matching the current selector, now and in the future. Set live: dlue 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 an 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

update

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

Call the update method to manually update existing scrollbars to accomodate 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);

Call the scrollTo method to programmatically scroll the content to the position parameter. Position parameter can be a string (e.g. "#element-id", "bottom", "left" etc.), an integer indicating a number of pixels to scroll-to (e.g. 100), an array for y/x axis (e.g. [100,100]), a js/jQuery object, a function etc.

Examples

Scroll to the last element within your content

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

Scroll to element with id el-1

var elID="#el-1";
$(".content").mCustomScrollbar("scrollTo",elID);

scrollTo parameter

$(selector).mCustomScrollbar("scrollTo",String);
Scrolls to element position, string value can be any unique id, class etc.
$(selector).mCustomScrollbar("scrollTo","top");
Scrolls to top (vertical scrollbars)
$(selector).mCustomScrollbar("scrollTo","bottom");
Scrolls to bottom (vertical scrollbars)
$(selector).mCustomScrollbar("scrollTo","left");
Scrolls to left-end (horizontal scrollbars)
$(selector).mCustomScrollbar("scrollTo","right");
Scrolls to right-end (horizontal scrollbars)
$(selector).mCustomScrollbar("scrollTo","first");
Scrolls to first element’s position within the content
$(selector).mCustomScrollbar("scrollTo","last");
Scrolls to last element’s position within the content
$(selector).mCustomScrollbar("scrollTo",Integer);
Scrolls to number of pixels, e.g. $(selector).mCustomScrollbar("scrollTo",200);

Method option parameters

scrollInertia: Integer
Scroll-to animation speed, value in milliseconds. Example:
$(selector).mCustomScrollbar("scrollTo","bottom",{
  scrollInertia:3000
});
moveDragger: Boolean
Scroll scrollbar dragger (instead of content) to a number of pixels, values: true, false. Example:
$(selector).mCustomScrollbar("scrollTo",80,{
  moveDragger:true
});
callbacks: Boolean
Trigger user defined callbacks after scroll-to completes, values: true, false. Example:
$(selector).mCustomScrollbar("scrollTo","left",{
  callbacks:false
});
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
});

stop

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

Stops running scrolling animations. Usefull when you wish to interupt a previously scrollTo call.

disable

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

Calling mCustomScrollbar’s disable method will temporarily disable the scrollbar. Disabled scrollbars can be re-enable by calling the update method.

Method parameters

$(selector).mCustomScrollbar("disable",true);
Disable custom scrollbar and reset content’s scrolling position.

Example of using disable method

destroy

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

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

Example of using destroy method

Styling the scrollbars

Style your scrollbar(s) using the jquery.mCustomScrollbar.css file which contains the default scrollbar style plus a number of ready-to-use themes. You can directly change the default styling or you can keep it and add additional styles for each scrollbar.

You can have separate styling for each of your scrollbars on the same page, either by giving your content blocks different class names or ids or simply by targeting them in your css like this:

.mCSB_1_scrollbar .mCSB_dragger .mCSB_dragger_bar{
    /* 1st scrollbar dragger style... */
}
.mCSB_2_scrollbar .mCSB_dragger .mCSB_dragger_bar{
    /* 2nd scrollbar dragger style... */
}
.mCSB_3_scrollbar .mCSB_dragger .mCSB_dragger_bar{
    /* 3rd scrollbar dragger style... */
}

…and so on. Each content block in your document that has custom scrollbars gets automatically an additional unique class in the form of _mCS_+index number (e.g. _mCS_1) based on its index number within the DOM. Also, an additional id in the form of mCSB_+index number is generated for each .mCustomScrollBox div. This way you can easily target and style any scrollbar using its parent class name or id.

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. For 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
    }
});

Returning values

The script returns a number of values and objects related to scrollbar

  • 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)

Example

$("#content_1").mCustomScrollbar({
    callbacks:{
        whileScrolling:function(){
            myCustomFn(this);
        }
    }
});

function myCustomFn(el){
    var msg="Content inside the element with id '"+el.attr("id")+"' has scrolled "+mcs.topPct+"%";
  console.log(msg);
}

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.
http://opensource.org/licenses/MIT

Pages: 1 2


3,602 Comments

Post a comment

Comments pages: 1 54 55 56

  1. aaysha
    Posted on November 21, 2014 at 15:26 Permalink

    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

    Reply
    • malihu
      Posted on November 21, 2014 at 16:01 Permalink

      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.

      Reply
      • aaysha
        Posted on November 21, 2014 at 16:22 Permalink

        Thanks a lot, it’s working… :D

        Reply
        • malihu
          Posted on November 21, 2014 at 20:48 Permalink

          You’re welcome. I edited my answer above as I made an error and it wasn’t very clear.

          Reply
  2. abc
    Posted on November 21, 2014 at 13:08 Permalink

    dude, you’re awesome, especially taking so much time to help people using your plugin, with helpful and prompt replies.
    great work, man

    Reply
    • malihu
      Posted on November 21, 2014 at 13:38 Permalink

      Thanks! I try to make time each day for replies, support etc.

      Reply
  3. Elsa
    Posted on November 20, 2014 at 16:53 Permalink

    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.

    Reply
    • Elsa
      Posted on November 20, 2014 at 17:30 Permalink

      Update:

      The scroll bar shows when I hover the right border. Is this normal? or it should show always?

      Reply
      • malihu
        Posted on November 20, 2014 at 19:52 Permalink

        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.

        Reply
  4. badri
    Posted on November 20, 2014 at 12:03 Permalink

    It is not working for ie9 please help me sort this out.

    Reply
    • malihu
      Posted on November 20, 2014 at 15:20 Permalink

      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).

      Reply
    • badri
      Posted on November 20, 2014 at 16:21 Permalink

      wondows7 professional and ie9
      pelase dowload from link.
      https://www.dropbox.com/s/kiy1nc4nar3674e/zzzzz.html?dl=0

      Reply
      • malihu
        Posted on November 20, 2014 at 19:48 Permalink

        Your element (#article) needs a height (or max-height) value.

        Reply
        • badri
          Posted on November 21, 2014 at 07:22 Permalink

          It worked,Thank you!!!

          Reply
  5. Michael Bryzgalov
    Posted on November 20, 2014 at 03:45 Permalink

    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!

    Reply
    • malihu
      Posted on November 20, 2014 at 05:42 Permalink

      Thanks for the feedback!

      1. What would be the benefit of delete c[m] instead of delete 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 vs typeof 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.

      Reply
      • Michael Bryzgalov
        Posted on November 20, 2014 at 16:16 Permalink

        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)

        Reply
        • malihu
          Posted on November 20, 2014 at 18:34 Permalink

          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.

          Reply
  6. Sameer Ali
    Posted on November 19, 2014 at 13:43 Permalink

    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

    Reply
  7. Adi
    Posted on November 18, 2014 at 07:55 Permalink

    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!

    Reply
    • malihu
      Posted on November 18, 2014 at 12:09 Permalink

      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.

      Reply
      • Adi
        Posted on November 18, 2014 at 12:24 Permalink

        Thanks a lot again for such a professional plugin.

        Reply
  8. roabhi
    Posted on November 17, 2014 at 20:17 Permalink

    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!.

    Reply
    • malihu
      Posted on November 17, 2014 at 21:15 Permalink

      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; }

      Reply
      • roabhi
        Posted on November 19, 2014 at 13:56 Permalink

        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!.

        Reply
  9. Mirko
    Posted on November 17, 2014 at 14:20 Permalink

    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

    Reply
    • malihu
      Posted on November 17, 2014 at 16:31 Permalink

      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);

      Reply
  10. Maria
    Posted on November 17, 2014 at 12:46 Permalink

    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

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

      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() { ... });

      Reply
  11. tm
    Posted on November 15, 2014 at 10:23 Permalink

    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?

    Reply
    • malihu
      Posted on November 15, 2014 at 10:41 Permalink

      New content must be added inside .mCSB_container div and not directly inside your element, e.g. $("#element-id .mCSB_container").html(...);

      Reply
  12. Sean Loyless
    Posted on November 15, 2014 at 00:05 Permalink

    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?

    Reply
    • malihu
      Posted on November 15, 2014 at 02:54 Permalink

      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?

      Reply
      • Sean Loyless
        Posted on November 15, 2014 at 22:45 Permalink

        I did, and unfortunately it had no effect over horizontal swiping.

        Here’s a URL to see it: http://www.wellspringstones.com/cartography/wellness

        Reply
        • malihu
          Posted on November 16, 2014 at 23:25 Permalink

          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?

          Reply
          • Sean Loyless
            Posted on November 17, 2014 at 17:28 Permalink

            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?

        • malihu
          Posted on November 17, 2014 at 18:02 Permalink

          Unfortunately there’s no way to differentiate between mouse and touchpad with javascript.

          Reply
  13. Bizzaro
    Posted on November 14, 2014 at 12:13 Permalink

    Is there a way to get this to work with an iframe targeting pages on the same server?

    Reply
    • malihu
      Posted on November 14, 2014 at 12:18 Permalink

      See iframe_example.html in plugin archive (online demo: http://manos.malihu.gr/repository/custom-scrollbar/demo/examples/iframe_example.html)

      Reply
    • Bizzaro
      Posted on November 14, 2014 at 12:45 Permalink

      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

      Reply
      • malihu
        Posted on November 14, 2014 at 13:06 Permalink

        Your #iframe-container needs a height value (e.g. height: 300px;).

        Reply
        • Bizzaro
          Posted on November 14, 2014 at 17:54 Permalink

          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.

          Reply
          • malihu
            Posted on November 14, 2014 at 18:59 Permalink

            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).

  14. Vijay
    Posted on November 13, 2014 at 15:36 Permalink

    jQuery custom content scroller is very very slow in safari browser. can u give me the solution?

    Reply
    • malihu
      Posted on November 13, 2014 at 22:10 Permalink

      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?

      Reply
  15. Gavin
    Posted on November 13, 2014 at 06:31 Permalink

    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…

    Reply
    • malihu
      Posted on November 13, 2014 at 22:44 Permalink

      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?

      Reply
      • Gavin
        Posted on November 21, 2014 at 02:52 Permalink

        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.

        Reply
        • malihu
          Posted on November 21, 2014 at 12:53 Permalink

          I’ll check Chrome on Android and see if I can fix it on the next version. Thanks for the feedback :)

          Reply
        • Nick Jag
          Posted on November 21, 2014 at 21:24 Permalink

          I can confirm this issue, I was having the same problem in Chrome on Android. Other than that, script is incredible.

          Reply
  16. Ashil John
    Posted on November 13, 2014 at 05:15 Permalink

    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.

    Reply
    • malihu
      Posted on November 13, 2014 at 22:47 Permalink

      The margin-right: 380px; rule is for positioning website’s sidebar. I’m still working on a better solution though. Thanks for the feedback.

      Reply
  17. Dimitri
    Posted on November 13, 2014 at 00:44 Permalink

    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 !!

    Reply
    • malihu
      Posted on November 13, 2014 at 02:44 Permalink

      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 ;)

      Reply
      • Dimitri
        Posted on November 18, 2014 at 00:58 Permalink

        Oh yeeah ! It works, that was my fault >___<
        Thanks for the speed of answer and for the time you took on my issue ;)

        Reply
  18. Guy
    Posted on November 12, 2014 at 23:16 Permalink

    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

    Reply
    • malihu
      Posted on November 13, 2014 at 22:02 Permalink

      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).

      Reply
  19. Erin
    Posted on November 12, 2014 at 18:06 Permalink

    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?

    Reply
    • malihu
      Posted on November 12, 2014 at 21:03 Permalink

      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" });

      Reply
  20. Ishmael
    Posted on November 11, 2014 at 08:50 Permalink

    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.

    Reply
    • Ishmael
      Posted on November 11, 2014 at 08:52 Permalink

      This is the code I tried:

      <button class="contact-email-submit" type="submit" onclick="location.hash = '#contact-thank-you';">Send</button>

      Reply
  21. Henry
    Posted on November 11, 2014 at 03:44 Permalink

    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.

    Reply
    • Henry
      Posted on November 11, 2014 at 07:38 Permalink

      Here is the link to the issue http://jsfiddle.net/u9pxth1f/

      Thanks.

      Reply
      • Henry
        Posted on November 11, 2014 at 19:26 Permalink

        I had just solved my problem by calling .mCustomScrollbar(“update”) before working on .mCustomScrollbar(“scrollTo”) function.

        Reply
  22. Evgen
    Posted on November 10, 2014 at 15:14 Permalink

    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.

    Reply
    • Evgen
      Posted on November 10, 2014 at 15:17 Permalink

      You can see it here http://radio.micromir.com.ua/

      Reply
      • malihu
        Posted on November 11, 2014 at 19:34 Permalink

        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 } });

        Reply
        • Evgen
          Posted on November 14, 2014 at 16:19 Permalink

          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.

          Reply
          • malihu
            Posted on November 14, 2014 at 16:38 Permalink

            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).

        • Evgen
          Posted on November 14, 2014 at 16:51 Permalink

          Disabling updateOnContentResize leads to turning off the scrollbar at all.
          I made these changes on the live site so you can see them

          Reply
          • malihu
            Posted on November 14, 2014 at 17:20 Permalink

            Ok just re-enable updateOnContentResize

        • Evgen
          Posted on November 14, 2014 at 18:05 Permalink

          Re-enabled. But slider still does not work =(

          Reply
          • malihu
            Posted on November 14, 2014 at 19:09 Permalink

            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.

  23. mystica
    Posted on November 9, 2014 at 16:50 Permalink

    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!

    Reply
    • malihu
      Posted on November 10, 2014 at 04:58 Permalink

      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. */

      Reply
  24. Eugene
    Posted on November 8, 2014 at 06:18 Permalink

    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

    Reply
    • malihu
      Posted on November 8, 2014 at 14:40 Permalink

      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?

      Reply
      • Eugene
        Posted on November 9, 2014 at 13:27 Permalink

        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!

        Reply
        • malihu
          Posted on November 10, 2014 at 04:31 Permalink

          Hey,

          I saw what you mean and I did some tests with the files you posted. I’ll send you the feedback via email :)

          Reply
        • Kris
          Posted on November 20, 2014 at 22:12 Permalink

          I have the same problem :/ did you find a solution?

          Reply
          • malihu
            Posted on November 20, 2014 at 22:37 Permalink

            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; }); });

      • Eugene
        Posted on November 9, 2014 at 13:32 Permalink

        Sorry, this is a correct link to the online demo.

        Reply
  25. A6000
    Posted on November 7, 2014 at 16:50 Permalink

    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
    }
    });

    Reply
    • malihu
      Posted on November 8, 2014 at 00:34 Permalink

      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 ;)

      Reply
      • A6000
        Posted on November 9, 2014 at 01:42 Permalink

        Thanx a lot! It works! :) yay!

        Reply

Comments pages: 1 54 55 56

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>

css.php