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

Upgrade notice

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 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 translates 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: true 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: 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 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 true, 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='true']"
advanced:{ updateOnContentResize: boolean }
Update scrollbar(s) automatically on content, element or viewport resize. The value should be true (default) for fluid layouts/elements, adding/removing content dynamically, hiding/showing elements etc.
advanced:{ updateOnImageLoad: boolean }
Update scrollbar(s) automatically each time an image inside the element is fully loaded. The value should be true (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 true, will update scrollbars each time any element is changed. To disable (default) set to false.
theme: string
Set the scrollbar theme (plugin’s CSS contains ready-to-use themes). The default theme is "light"
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 trigger the onTotalScroll callback 100 pixels before the end of scrolling is reached.
callbacks:{
    onTotalScrollBackOffset: Integer
}
Set an offset for the onTotalScrollBack option. For example, setting onTotalScrollBackOffset: 100 will trigger the onTotalScrollBack callback 100 pixels before the beginning of scrolling is reached.
callbacks:{
    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:{
    alwaysTriggerOffsets: boolean
}
Set the behavior of calling onTotalScroll and onTotalScrollBack offsets. By default, callback offsets will trigger repeatedly while content is scrolling within the offsets. Set alwaysTriggerOffsets: false when you need to trigger onTotalScroll and onTotalScrollBack callbacks once, each time scroll end or beginning is reached.
live: boolean, string
Enable or disable applying scrollbar(s) on all elements matching the current selector, now and in the future. Set live: true when you need to add scrollbar(s) on elements that do not yet exist in the page. These could be elements added by other scripts or plugins after some action by the user takes place (e.g. lightbox markup may not exist untill the user clicks 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
});

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

Post a comment

Comments pages: 1 14 15 16

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

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

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

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

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

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

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

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

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

      any ideas? or am I overthinking this….

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

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

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

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

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

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

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

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

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

      Hello,

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

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

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

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

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

    Mark

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        Ok thank you!

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

    Hello,

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

    Thanks.

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

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

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

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

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

    With the new Version UpdateOnContentResize dont work.

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

    Before i dont need destroy the bar first.

    Sorry for my english.

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

    Hi!

    Firstly, thanks for the great work! Really! :)

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

    Thanks for your reply!

    bye,
    Adam

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

      Hello,

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

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

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

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

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

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

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

    Example:

    test1.html contains a table of Sponsors

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

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

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

    Any Idea?

    best
    Christian

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

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

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

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

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

      Code example:

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

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

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

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

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

    for instance:

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

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

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

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

    i am using Version: 3.0.3 and my code is

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

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

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

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

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

    thanks

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

    Hi, great plugin!

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

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

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

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

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

      Hello,

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

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

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

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

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

    Thanks.

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

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

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

    Hi,

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

    How can i implement the scrollTo function.

    Thanks & regards,
    Vijayan M

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

      Hello,

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

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

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

        Hi,

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

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

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

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

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

        Thanks & regards,
        Vijayan M

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

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

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

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

            Thanks malihu

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

            its working fine :)

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

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

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

      Hi,

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

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

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

    Hello!
    This plugin looks beautiful!

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

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

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

      I updated the fiddle to show what i mean:

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

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

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

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

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

    Good job, great plugin, Thank You!

    Reply
  22. Kamel
    Posted on July 30, 2014 at 00:48 Permalink

    Great plugin ! But it doesn’t work for me :/ All files are included, but I don’t know why it’s not working. I followed this tutorial but for him, it works : https://www.youtube.com/watch?v=niEG065e8Aw

    What could me my problem ?

    Reply
    • malihu
      Posted on August 8, 2014 at 20:29 Permalink

      Make sure all plugin files (css and js) are included in your page (make sure paths are correct).
      Check if you’re calling mCustomScrollbar on existing element(s) and make sure your element(s) have a height or max-height set.

      Check your page with browser developer tools and see if you get any console errors.

      Reply
  23. Srdjan
    Posted on July 29, 2014 at 16:05 Permalink

    Hi,

    I want to have 2 horizontal scrollbars. The first on the top and the second on the bottom.
    Is ti possible to achieve this with your jQuery plugin?

    Thanks in advance!

    Reply
    • malihu
      Posted on July 29, 2014 at 20:42 Permalink

      Not really. You can’t have two same-axis scrollbars on the same element.

      Reply
  24. Alexey
    Posted on July 29, 2014 at 11:29 Permalink

    Hi,

    First of all : thanks for a really nice plugin having a very good performance!

    I have a problem, that mouse wheel doesn’t work, when the mouse pointer points to scrollbar itself. Is it possible to change it?

    Thanks,

    Alexey

    Reply
    • malihu
      Posted on July 29, 2014 at 20:40 Permalink

      Hi,

      When scrollbarPosition option is set to “inside” (default), the mouse-wheel scrolling works when hovering over the scrollbat itself. When scrollbarPosition is set to “outside”, it doesn’t work as the scrollbar is placed outside of the content wrapper element that triggers mouse-wheel scrolling.

      So your only option is to change the scrollbarPosition option parameter.

      Reply
  25. Cseh Szabolcs
    Posted on July 23, 2014 at 16:04 Permalink

    Hello there,

    i love this plugin, its very cool! But there is somethink, what should be changed:

    [code]
    $("#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+"%"; //<-- mcs is global available in the window-object
    console.log(msg);
    }
    [/code]

    The variable 'mcs' is available in the window.object. But that really don't belong there. This sould be moved in the jQuery-data of the element or something:

    [code]
    // instead of:
    console.log(msc)
    // should be like this:
    console.log($("#content_1").data('msc'));
    [/code]

    And sorry for my terrible english :-)

    Reply
    • malihu
      Posted on July 29, 2014 at 20:56 Permalink

      Hello,

      Since version 3.0.0 the mcs object is moved in the actual element instead of window (this.mcs):
      $("#content_1").mCustomScrollbar({ callbacks:{ whileScrolling:function(){ console.log(this.mcs.top); } } });

      Reply
  26. Steven
    Posted on July 23, 2014 at 06:03 Permalink

    Odd behavior…..only in Firefox though.

    I consumed an rss feed and got everything to work perfectly in a single page….whether it is IE, FF or Chrome. View the page looks great.

    I then created another page and wanted the feed to show up within a div on the new page…..so I tried using jQuery to display a web page within a div…..works great in IE and Chrome, but not Firefox….the scroll bar shows the default scroll bar.

    Also…tried iframe and that works ok with IE, FF and Chrome too….

    Here is the jQuery code I used to try and bring the web page into a div (trying to use this instead of iframe).

    Here is the jQuery code I used.

    HTML:

    jQuery:

    $(document).ready(function(){

    $(“#frameOne”).load(“page2.shtml”);

    });

    Not sure why I can’t get it to work.

    Reply
  27. shareef
    Posted on July 23, 2014 at 02:19 Permalink

    When I put twitter widget within the scrolled div, the widget disappear.
    but when I put it outside the scrolled div ,the widget appears.
    Why ? How to fix that ?

    thanks a lot to malihu team..

    Reply
    • logik
      Posted on August 7, 2014 at 06:12 Permalink

      I am having this same issue. I’d like to know if this ever gets solved.

      Reply
    • malihu
      Posted on August 7, 2014 at 07:12 Permalink

      This happens due to how twitter api works. To make twitter widgets render within elements with scrollbar do the following:

      Place the anchor tag (<a class="twitter-timeline"...>...</a>) of the twitter widget code inside the scrolled div. Place only the anchor tag and NOT the script tag!

      Copy the code of the twitter widget script tag (!function(d,s,id){...}(document,"script","twitter-wjs");) and paste it below your mCustomScrollbar function call inside window load function.

      This will make your widgets work and initialized correctly.

      Reply
      • Steve
        Posted on August 14, 2014 at 05:37 Permalink

        I too was having issues with trying to get the scroller to work with the twitter widget. I found this code to not work for me.
        (!function(d,s,id){...}(document,"script","twitter-wjs");)

        What I did to make it work was put the semi-colon outside the last paren….like this…

        (!function(d,s,id){...}(document,"script","twitter-wjs"));

        Just an FYI in case someone else came across this.

        Thank you for the plugin…it works great.

        Reply
  28. ali
    Posted on July 22, 2014 at 11:55 Permalink

    thanks man… i’m gonna use it on my website… http://www.khabartek.ir

    Reply
  29. Martin
    Posted on July 22, 2014 at 11:42 Permalink

    Really cool looking plugin but I run into problems with it and have no idea what’s going wrong.
    The examples work well but whenever I try to implement the faeture(s) into my own page the custom bars won’t show up. I must say that I’ve altered the directory structure (directory “css” and “js” for corresponding files) and adjusted the source code for the page to fit with the new determined structure but the bars aren’t there.

    So I grabbed one of the example html files and put it into the root of my project folder, altered the source code. Nothing happened, the same effect, style.css ist working but not the bars.

    So my question is: What have I missed? Is there a way to reorganize the folder structure to my presonal needs?

    Reply
  30. Wendi
    Posted on July 21, 2014 at 00:31 Permalink

    wonderful plugin, but…

    i love this plugin and have used it numerous times without issue. today, however, is different. it is working just fine until i add this link to my header:

    this is a google font. with this in the header, i see the text flash on the page, then quickly disappear. i do not see the scrollbar either.

    any ideas??

    Reply
  31. Evgeni
    Posted on July 19, 2014 at 17:14 Permalink

    I just found that amazing plugin and I want it to try it on my website gallery.

    I manage to run it with except that I can run only the Y scroll but not the X scroll
    which I need.

    I am posting link and I will be happy to explain me why its not working.

    Brgds
    Evgeni

    Reply
  32. sandeep
    Posted on July 19, 2014 at 08:19 Permalink

    I am using your scroll bar for my sidebar in my project i am adding it to tag But it is not working.. FOr every time i am getting

    <nav id="sidebar" class="mCustomScrollbar _mCS_1"> <div id="mCSB_1" class="mCustomScrollBox mCS-light-thin" style="position:relative; height:100%; overflow:hidden; max-width:100%;"> <div class="mCSB_container mCS_no_scrollbar" style="position: relative; top: 0px;"></div>

    Plz hel me….

    Reply
    • Nicolas
      Posted on July 24, 2014 at 11:21 Permalink

      I have exactly the same problem, did you find a fix for this?

      I am using dotclear for my blog.

      On the simple html/js/css template I had no issue making work this awesome plugin, but on the dotclear version it doesnt work anymore and show me “mCS_no_scrollbar” div.

      Reply
  33. sandeep
    Posted on July 19, 2014 at 08:17 Permalink

    I am using your scroll bar for my sidebar in my project i am adding it to tag But it is not working.. FOr every time i am getting

    Plz hel me….

    Reply
  34. Ian
    Posted on July 19, 2014 at 00:07 Permalink

    I have interesting problem where call to mCustomScrollbar (V2.8) only works once.

    This is in Adobe EdgeCC. It is worth noting that this problem did *not* occur in prior versions of Edge.

    The following code will work the first time it is executed, but the next time the timeline returns, the html is displayed, but without the scrollbar.
    Any ideas what changed in either EdgeCC, or mCustomScrollbar (V2.8) ?
    Thanks
    sym.$("Contents").html("<p>Page1 Dolor sit amet, etc...</p>"); sym.$("Contents").mCustomScrollbar({ autoDraggerLength:true, scrollInertia:800, mouseWheel:{ enable: true, scrollAmount: 60 }, scrollButtons:{ enable: false, } });

    Reply
  35. Tom
    Posted on July 18, 2014 at 21:47 Permalink

    Hey guys! I am trying to add this scrollbar to my textarea. I cannot seem to figure this out!

    Thanks for any help!

    Reply
  36. Chris
    Posted on July 18, 2014 at 13:08 Permalink

    This an amazing plugin, thank you :)

    Reply
  37. Viktor
    Posted on July 15, 2014 at 16:48 Permalink

    Hello Dears
    Please help me
    I try use this plugin with JQuery AJAX
    When i use method append(data) – no problem, scroll updated, but my site have just one main where i show all content. For it i use innerHTML or html(data). I must clear main div for show content via AJAX
    In zip example ajax just add content, but it no need for me
    How i can call scroll after replacement content?

    Ajax code
    (function ($) { $(window).load(function () { $("#body").delegate("a[rel='link']", "click", function (e) { e.preventDefault(); var url = $(this).attr("href"); $.ajax({ url: url, type: 'POST', datatype: 'xml', data: 'ajax=1', success: function (data) { $('#content').html(data); $('#content').mCustomScrollbar(); } }); window.history.pushState(null, null, url); return false; }); if (location.href != (location.protocol + '//' + location.host + '/')) { $.ajax({ url: location.href, type: "POST", datatype: 'xml', data: 'ajax=1', success: function (data) { $('#content').html(data); $("#content").mCustomScrollbar(); } }); } $(window).bind('popstate', function () { if (location.href != (location.protocol + '//' + location.host + '/')) { $.ajax({ url: location.href, type: "POST", datatype: 'xml', data: 'ajax=1', success: function (data) { $('#content').html(data); $("#content").mCustomScrollbar(); } }); } else { document.getElementById('content').innerHTML = ''; } }); }); })(jQuery);

    <table class="all_content" id="all_content"><tr><td style="width: 0%" id="first_td"></td> <td style="width: 20%"> <div class="menu" id="menu"> <div id="menu_ico" class="menu_ico2"> <div class="menu_head"> <img alt="Верхний логотип" src="/img/top_logo.png" /> </div> <div class="menu_main_icon"> <img alt="Основной логотип" src="/img/main_logo.png" /> </div> <div class="menu_flo" id="menu_flo_1"> <div class="login_button" id="logout" onclick="login(this)">Выход</div> </div> </div><div class="menu_menu" id="menu_menu"><ul> <li><a href="/test.php" class="menu_link" rel='link' ><?php echo $m1;?></a></li> <li><a href="/test2.php" class="menu_link" rel='link' ><?php echo $m2;?></a></li> <li><a href="/test3.php" class="menu_link" rel='link' ><?php echo $m3;?></a></li> <li><a href="/link/top_link.php" class="menu_link" rel='link' ><?php echo $m4;?></a></li> <li><a href="/test6.php" class="menu_link" rel='link' ><?php echo $m5;?></a></li> <li><a href="/test7.php" class="menu_link" rel='link' ><?php echo $m6;?></a></li> <li><a href="/link/contact.php" class="menu_link" rel='link' ><?php echo $m7;?></a></li> </ul> </div> </div> </td> <td class="td_content"><div class="content" id="content"></div> </td></tr></table>

    Reply
  38. Leandro Beni
    Posted on July 14, 2014 at 05:29 Permalink

    Great job this plugin!

    It is sad that the examples are a messy… I spent a lot of time trying to use the RTL example and I give up…
    Can someone help me?

    Reply
  39. JSNewbie
    Posted on July 12, 2014 at 10:46 Permalink

    Hi,
    I’m using the pluging for scrolling in table cells(with “snapAmount” option) and all is working great, except one thing:

    Is there a way to detect which cell is currently visible and add it a class or something similiar to mark it red for example?

    Reply
  40. Ravichandran Jayaramegowda
    Posted on July 10, 2014 at 16:59 Permalink

    Beautiful scrollers collection. Awesome works. Thanks for providing a good tutorial explaining each component in brief. This is a must have component for developing any web applications.

    Cheers,
    Ravi

    Reply
  41. Michael
    Posted on July 9, 2014 at 23:43 Permalink

    Hi,

    Nice plugin. I noticed a possible bug with the new 3.x library, as well as the documentation. Previously in 2.x, totalScrollOffset was specified in pixels, so specifying 20px would result in the onTotalScroll() event being called when the slider reaches 20px from the bottom of the panel. However, in 3.x I noticed in the JS code that a scrollRatio is being applied to the passed in totalScrollOffset. This changes the behavior of totalScrollOffset. I either need to know the size of my container and my content and calculate the scrollRatio accordingly (which isnt a good solution, since i usually dont have that info when im setting up the scrollbar) or the calculation should change to consider the value I pass in as pixels relative to the dragger container and not the content container.

    Thanks,
    Michael

    Reply
  42. Marcello
    Posted on July 9, 2014 at 19:53 Permalink

    Hi there!

    thanks for this awesome tool. It works where I’ve got static content.
    Yet when I try to apply it to a div the text-content of which is loaded via JQuery, the standard scrollbar appears.
    Is there a way to get the customised scrollbar to appear?

    Reply
    • Guido
      Posted on July 16, 2014 at 12:05 Permalink

      You need to add the scrollbar in the success function of your asynchronous call.

      Reply
  43. Matjaz
    Posted on July 8, 2014 at 10:26 Permalink

    Cannot get the scrollbar to function with keyboard (up/down)

    jqElm.find(‘.List-Modal’).mCustomScrollbar({
    theme: “light-2″,
    scrollbarPosition: ‘outside’,
    advanced: {
    keyboard: {
    scrollType: ‘stepped’,
    scrollAmount: 38
    }
    }
    });

    and tried also this

    jqElm.find(‘.List-Modal’).mCustomScrollbar({
    theme: “light-2″,
    scrollbarPosition: ‘outside’,
    keyboard: {
    scrollType: ‘stepped’,
    scrollAmount: 38
    }
    });

    Reply
  44. Guido
    Posted on July 2, 2014 at 14:26 Permalink

    Hello,

    first of all I want to thank you very much for that awsome plugin. My question is, whether it is possible to decrease the space between the vertical scrollbar and the content. I have very small boxes to fill with content and there is each pixel important.
    Best Regards
    Guido

    Reply
  45. IşıkFX
    Posted on July 1, 2014 at 14:31 Permalink

    Thank for post !

    Reply
  46. Niko Oviedo
    Posted on July 1, 2014 at 09:17 Permalink

    GREAT JOB! This plugin, work’s on ie browser? Saluts!

    Reply
  47. sdfdf
    Posted on June 30, 2014 at 13:30 Permalink

    sfdsfdsfdsfdsf

    Reply
  48. Migiyaka
    Posted on June 28, 2014 at 03:31 Permalink

    Hey, I’m having a problem that sometimes, scrollTo doesn’t scroll to desired coordinates. If you received the website in the comment, it’s called when a portfolio item is clicked, and when you click on an item in “related projects” section – sometimes it scrolls to the top (desired behavior), and sometimes it cuts off some 100-200px from the top. Any help would be appreciated.

    Reply
  49. Alexandre P
    Posted on June 27, 2014 at 16:25 Permalink

    Is it possible with the current version to be able to vertically scroll an horizontal scrollbar and still be able to scroll down the page? Right now if I try to scroll down while touching the content it restricts me to the x-axis. I read in the comments that you were planning on adding a functionality for this about a year ago. Has it yet been added in? Can’t seem to find anything else that could solve my problem.

    Reply
  50. raiffy
    Posted on June 27, 2014 at 15:39 Permalink

    Hi,

    first of all, congrats for such amazing tool. It works almost flawlessly except for the snapAmount (y scroll, version 3.0.x). If (and only if) I have a two rowed content, it never scrolls to the second row by using the mousewheel. Every element has the same height which I used as the snapAmount. Any idea? I’m posting the code:

    var step = (modo == “mural”)?(parseInt(Y.one(“#itens”).getComputedStyle(“height”))):0;

    $(“#itens”).mCustomScrollbar({
    snapAmount: passo,
    autoHideScrollbar: true,
    scrollInertia: false,
    setHeight: passo – 10,
    advanced:{
    keyboard:{ scrollType: “stepped”}
    });

    thanks!

    Reply
    • raiffy
      Posted on June 27, 2014 at 15:41 Permalink

      the ‘setHeight’ line is just a test, plase ignore it… and suppose modo == “mural”

      Reply
  51. Alex
    Posted on June 26, 2014 at 16:43 Permalink

    Simple question, when I try to use the return values (left, leftPct, top, topPct), this.mcs is always undefined at the beginning. For it to have a value I have to either move one of the scrollbar’s slider or try and get its value once with this.mcs.[...] and then it suddenly isn’t undefined. Just wondering if I’m doing something wrong here.

    ss.mCustomScrollbar(“scrollTo”, (function(el) {
    console.log(el.mcs);
    return 0;
    })(this));

    Also, the object el.mcs returns me somehow only has these values:

    draggerLeft: 0
    draggerTop: 0
    left: 0
    leftPct: 0
    top: 0
    topPct: 0

    No content. Why is that?

    Reply
    • Alex
      Posted on June 26, 2014 at 18:10 Permalink

      Never mind, didn’t realise I could just use this directly into the callback function (DUHH).

      Thanks a lot for this great plugin nonetheless :P

      Reply
      • Alex
        Posted on June 26, 2014 at 18:13 Permalink

        Never mind again, I still have the same problem when I use “this” directly.

        Reply
        • Alex
          Posted on June 26, 2014 at 18:20 Permalink

          Well a temporary fix I found is calling this line after initializing the scrollbar:

          /* Fixes the undefined value of this.mcs */
          $(“.mCustomScrollbar”).mCustomScrollbar(“scrollTo”, 0);

          Reply
          • ellmo
            Posted on July 15, 2014 at 15:05 Permalink

            I’m having the same problem here,

            this.mcs is always undefined so scrolling callbacks are useless to me

Comments pages: 1 14 15 16


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