web design

jQuery custom content scroller

jQuery custom content scroller

Custom scrollbar plugin that’s fully customizable with CSS. Features vertical/horizontal scrolling, mouse-wheel support (via jQuery mousewheel plugin), scrolling buttons, scroll inertia with easing, auto-adjustable scrollbar length, nested scrollbars, scroll-to functionality, user defined callbacks and much more.

Current version 2.8.2 (Changelog)

How to use it

Download the archive which contains all plugin files and examples. Extract and upload jquery.mCustomScrollbar.concat.min.js, jquery.mCustomScrollbar.css and mCSB_buttons.png to your web server.

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

<link href="jquery.mCustomScrollbar.css" rel="stylesheet" type="text/css" />

Include jQuery library (if your project doesn’t use it already) and jquery.mCustomScrollbar.concat.min.js at the very bottom of your document, just before the closing body tag

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

After files inclusion, call mCustomScrollbar function on the element you want to add custom scrollbars. The example below adds scrollbars to elements with class name content

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

Your .content element(s) (or any other element you’re attaching the custom scrollbar) should have a typical styling of an overflowed block, e.g. a height (or max-height) value, overflow: auto (or hidden) and its content should be long enough to require a scrollbar.

To add a horizontal scrollbar, style your element accordingly (give it a width value and a wide enough content) and set the horizontalScroll option parameter of mCustomScrollbar to true

$(".content").mCustomScrollbar({
    horizontalScroll:true
});

jquery.mCustomScrollbar.css contains few ready-to-use scrollbar themes that you can apply easily on your scrollbars by setting the theme option parameter to the theme name you want

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

Detailed usage guide

jquery.mCustomScrollbar.css contains the basic styling of the custom scrollbar and 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 is a single PNG image file that contains the default, plus some additional sets for the up, down, left and right arrows used by the scrollbar buttons. I’ve created a single file in order to use CSS sprites for the button icons (defined in jquery.mCustomScrollbar.css). The plugin archive contains the PSD source (source_files/mCSB_buttons.psd) so you can add your own if you wish.

jquery.mCustomScrollbar.concat.min.js is the main plugin file which contains the custom scrollbar script as well as all necessary scripts, plugins etc. concatenated and minified. This file should be included after loading the jQuery library (the javascript library used by the plugin).

Both jQuery and plugin files can be included inside the head or body tags of your document. Including scripts at the bottom of html documents (e.g. just before the closing body tag) is usually recommended for better performance. You can load jQuery via Google’s CDN (why?) or from your own directory (the archive contains a copy of jQuery inside js folder).

The way I recommend and what I’ve used in all demos and examples is loading jQuery from a CDN (e.g. Google) and have a local copy to fallback in case CDN files won’t load

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script>!window.jQuery && document.write(unescape('%3Cscript src="js/minified/jquery-1.9.1.min.js"%3E%3C/script%3E'))</script>

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.9.1/jquery.min.js"></script>
<script>!window.jQuery && document.write(unescape('%3Cscript src="js/minified/jquery-1.9.1.min.js"%3E%3C/script%3E'))</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, ensuring the script calculates correctly content’s length.
If the scrollbars apply to content that has no elements with external sources (e.g. images, objects etc.) you may want to call mCustomScrollbar on document ready (so 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 have different options (configuration and option parameters explained below) for each selector

<script>
  (function($){
    $(window).load(function(){
      $("#content-1").mCustomScrollbar({
        horizontalScroll:true,
        autoDraggerLength:false
      });
      $("#content-2").mCustomScrollbar({
        mouseWheel:false,
        scrollButtons:{
          enable:true
        }
      });
    });
  })(jQuery);
</script>

Important notes

In order for the custom scrollbar to work correctly, your content block must be visible (i.e. should not have display:none) and its content should be fully loaded. Otherwise you must call plugin’s update method after the above conditions are met.

Hidden content blocks (either by CSS display property or jQuery $.hide()) have zero dimensions, so calling mCustomScrollbar function on them will not work. Instead, you should call the function after your elements become fully visible, so the script calculates content length correctly and apply/update the scrollbar (see live example).

If you load your content dynamically (e.g. via ajax) you must also call mCustomScrollbar function (or its update method) after content is fully loaded (e.g. on ajax success). The same applies when you programmatically change the content of elements with custom scrollbars (see ajax demo).

If for any reason you cannot insert your own code in other scripts or simply don’t know where to put it, set plugin’s updateOnContentResize option parameter to true

$(".content").mCustomScrollbar({
    advanced:{
        updateOnContentResize: true
    }
});

The above will call automatically the update method if your content’s length is changed.

Configuration

mCustomScrollbar function can get the following option parameters in order to customize scrollbar behavior and functionality

set_width: false
Set the width of your content (overwrites CSS width), value in pixels (integer) or percentage (string).
set_height: false
Set the height of your content (overwrites CSS height), value in pixels (integer) or percentage (string).
horizontalScroll: Boolean
Add horizontal scrollbar (default is vertical), values: true, false.
scrollInertia: Integer
Scrolling inertia (easing), value in milliseconds (0 for no scrolling inertia).
mouseWheel: Boolean
Mouse-wheel support, values: true, false.
mouseWheelPixels: "auto"
Mouse-wheel scrolling pixels amount, value in pixels (integer) or “auto” (script calculates and sets pixels amount according to content length).
autoDraggerLength: Boolean
Auto-adjust scrollbar height/width according to content, values: true, false.
autoHideScrollbar: Boolean
Automatically hide the scrollbar when idle or mouse is not over the content.
scrollButtons:{
    enable: Boolean
}
Scroll buttons support, values: true, false.
scrollButtons:{
    scrollType: String
}
Scroll buttons scroll type, values: "continuous" (scroll continuously while pressing the button), "pixels" (scroll by a fixed number of pixels on each click)
See both scroll types in action.
scrollButtons:{
    scrollSpeed: "auto"
}
Scroll buttons continuous scrolling speed, integer value or “auto” (script calculates and sets the speed according to content length).
scrollButtons:{
    scrollAmount: Integer
}
Scroll buttons pixels scrolling amount, value in pixels.
advanced:{
    updateOnBrowserResize: Boolean
}
Update scrollbars on browser resize (for fluid content blocks & layouts based on percentages), values: true, false. Set to false only when your content has fixed dimensions.
advanced:{
    updateOnContentResize: Boolean
}
Auto-update scrollbars on content resize (useful when adding/changing content programmatically), values: true, false
Setting this to true makes the script check for content length changes (every few milliseconds) and automatically call plugin’s update method to adjust the scrollbar accordingly.
advanced:{
    autoExpandHorizontalScroll: Boolean
}
Auto-expanding content’s width on horizontal scrollbars, values: true, false
Set to true if you have horizontal scrollbar on content that will change on-the-fly. Demo contains blocks with images and horizontal scrollbars that use this option parameter.
advanced:{
    autoScrollOnFocus: Boolean
}
Auto-scrolling on elements that have focus (e.g. scrollbar automatically scrolls-to form textfields when the TAB key is pressed), values: true, false.
advanced:{
    normalizeMouseWheelDelta: Boolean
}
Normalize mouse-wheel delta (-1/1), values: true, false.
contentTouchScroll: Boolean
Additional scrolling method by touch-swipe content (for touch enabled devices), values: true, false.
callbacks:{
    onScrollStart: function(){}
}
User defined callback function, triggered on scroll start event. You can call your own function(s) each time a scroll event begins (callbacks demo). Example:
callbacks:{
  onScrollStart:function(){
    console.log("scrolling started...");
  }
}
callbacks:{
    onScroll: function(){}
}
User defined callback function, triggered on scroll event. Call your own function(s) each time a scroll event completes (callbacks demo). Example:
callbacks:{
  onScroll:function(){
    console.log("content scrolled...");
  }
}
callbacks:{
    onTotalScroll: function(){}
}
User defined callback function, triggered when scroll end-limit is reached (callbacks demo). Example:
callbacks:{
  onTotalScroll:function(){
    console.log("scrolled to end of content.");
  }
}
callbacks:{
    onTotalScrollBack: function(){}
}
User defined callback function, triggered when scroll beginning is reached (callbacks demo). Example:
callbacks:{
  onTotalScrollBack:function(){
    console.log("scrolled back to the beginning of content.");
  }
}
callbacks:{
    onTotalScrollOffset: Integer
}
Scroll end-limit offset, value in pixels (see example).
callbacks:{
    onTotalScrollBackOffset: Integer
}
Scroll beginning offset, value in pixels.
callbacks:{
    whileScrolling: function(){}
}
User defined callback function, triggered while scrolling (callbacks demo). Example:
callbacks:{
  whileScrolling:function(){
    console.log("scrolling...");
  }
}
theme: String
Set a scrollbar ready-to-use theme (see all themes).

Scrollbar markup

The script generates all necessary markup for the javascript scrollbar

<div class="content mCustomScrollbar _mCS_1">
  <div class="mCustomScrollBox" id="mCSB_1">
    <div class="mCSB_container">
      <!-- content -->
    </div>
    <div class="mCSB_scrollTools">
      <a class="mCSB_buttonUp"></a>
      <div class="mCSB_draggerContainer">
        <div class="mCSB_dragger">
          <div class="mCSB_dragger_bar"></div>
        </div>
        <div class="mCSB_draggerRail"></div>
      </div>
      <a class="mCSB_buttonDown"></a>
    </div>
  </div>
</div>

The original content resides inside .mCSB_container div which is also the scrollbale element. .mCSB_scrollTools contains the scrollbar and scrolling buttons. .mCSB_buttonUp and .mCSB_buttonDown are generated only in case you enable scroll buttons (see Configuration).

The markup for content blocks with horizontal scrollbars gets an additional mCSB_horizontal class and the scrolling buttons become .mCSB_buttonLeft and .mCSB_buttonRight respectively

<div class="content mCustomScrollbar _mCS_1">
  <div class="mCustomScrollBox mCSB_horizontal" id="mCSB_1">
    <div class="mCSB_container">
      <!-- content -->
    </div>
    <div class="mCSB_scrollTools">
      <a class="mCSB_buttonLeft"></a>
      <div class="mCSB_draggerContainer">
        <div class="mCSB_dragger">
          <div class="mCSB_dragger_bar"></div>
        </div>
        <div class="mCSB_draggerRail"></div>
      </div>
      <a class="mCSB_buttonRight"></a>
    </div>
  </div>
</div>

Plugin methods

update

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

Calling plugin’s update method will update existing scrollbars (the script will re-calculate scrollbar length, scrolling amount etc. according to scrollable content).
You should call this method within your scripts each time you change your content dynamically (for example, when adding or removing elements with javascript, inserting new content via ajax, hiding/showing content blocks etc.).

Examples

Appending plain text content on blocks with custom scrollbars

$(".content .mCSB_container").append("<p>New content...</p>");
$(".content").mCustomScrollbar("update");

Appending an image on a block with custom scrollbars

$("#content-1 .myImagesContainer").append("<img src='myNewImage.jpg' />");
$("#content-1 .myImagesContainer img").load(function(){
  $("#content-1").mCustomScrollbar("update");
});

Animating the height of blocks with custom scrollbars

$(".content").animate({height:800},"slow",function(){
  $(this).mCustomScrollbar("update");
});

Always call the update method after newly added content is fully loaded and/or animations are completed.

scrollTo

Usage $(selector).mCustomScrollbar("scrollTo",position);

Calling plugin’s scrollTo method will automatically scroll the content to the position parameter. Scroll-to position can be a string (e.g. "#element-id", "bottom", "left" etc.) or an integer, indicating a number of pixels to scroll-to.

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 (check the stylesheet inside demo_files that I’ve used to style the scrollbars for the demo and examples).

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:

._mCS_1 .mCSB_scrollTools .mCSB_dragger .mCSB_dragger_bar{
    /* 1st scrollbar dragger style... */
}
._mCS_2 .mCSB_scrollTools .mCSB_dragger .mCSB_dragger_bar{
    /* 2nd scrollbar dragger style... */
}
._mCS_3 .mCSB_scrollTools .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();
        }
    }
});

function myCustomFn(){
    console.log(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 current element as jQuery object
  • mcs.top – content’s top position (pixels)
  • mcs.left – content’s left position (pixels)
  • mcs.draggerTop – scrollbar dragger’s top position (pixels)
  • mcs.draggerLeft – scrollbar dragger’s left position (pixels)
  • mcs.topPct – content vertical scrolling percentage
  • mcs.leftPct – content horizontal scrolling percentage

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

You can see all callbacks in action on this demo

Plugin dependencies

Custom scrollbar plugin requires the following in order to work

Mousewheel plugin (by Brandon Aaron) adds cross-browser mouse-wheel support for the scrollbar.

The production-ready plugin file – jquery.mCustomScrollbar.concat.min.js contains the plugin script and mousewheel plugin, concatenated and minified.
jquery.mCustomScrollbar.js contains the plugin script (uncompressed) and loads dependencies (all except jQuery) via CDN.
All script files and dependencies are available separately (uncompressed and minified version included) inside js directory.

Loading scripts separately

If you prefer to load the plugin script and each dependency separately (example included in the archive), you can do the following

<!-- Google CDN jQuery with fallback to local -->
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script>!window.jQuery && document.write(unescape('%3Cscript src="js/minified/jquery-1.9.1.min.js"%3E%3C/script%3E'))</script>
<!-- CloudFlare CDN mousewheel plugin with fallback to local -->
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery-mousewheel/3.0.6/jquery.mousewheel.min.js"></script>
<script>$.event.special.mousewheel || document.write('<script src="js/minified/jquery.mousewheel.min.js"><\/script>')</script>
<!-- custom scrollbars plugin -->
<script src="js/minified/jquery.mCustomScrollbar.min.js"></script>

Each script loads via CDN and falls-back to local files in case CDN fails.

License

You are free to use, study, improve and modify this script wherever and however you like.
Creative Commons License All works are licensed under GNU General Public License, GNU Lesser General Public License or Creative Commons Attribution 3.0 Unported License.

Pages: 1 2


2,493 Comments

Post a comment

Comments pages: 1 10 11 12

  1. jack
    Posted on May 22, 2013 at 11:04 Permalink

    There is an issue with autohide,

    If you have the scrollbar attached to a div (e.g. body) and nother scrollbar inside that div then even with autohide, the topmost scrollbar will always show.

    Would it be possible to make it so autohide would hide the scrollbar always and only show it while scrolling with a fadein/out effect like it happens with mobile scrollbars? Or maybe make it a new option,

    autoHide: false //always show
    autoHide: ‘hover’ //show on hover and scrolling
    autoHide: ‘scroll’ //show while scrolling only

    Also a autoHideEffect would be useful for specifying the show/hide effect.

    autoHideEffect: false //instantly show/hide on autohide
    autoHideEffect: ‘fade’ //fade in/out on autohide

    Reply
  2. Rafal Again...
    Posted on May 21, 2013 at 20:21 Permalink

    Hello Again,
    I’ve got a little problem.. i’m using scroll bar on my “content” page so when scroll first page to bottom, all others sites opens on bottom. Please help me.

    Reply
  3. Jake
    Posted on May 21, 2013 at 17:28 Permalink

    Hi,
    I’m trying to completely prevent any scrolling from happening when the scroll buttons are click, unless certain conditions are met. I’ve gotten it close, but it still scrolls down maybe 5-7 pixels or so. I’m preventDefault’ing and using the “stop” method. This residual scrolling also doesn’t seem to have any smooth animation like normal scrolling for the plugin, seems to happen instaneously. Any thoughts?

    Thanks

    Reply
    • Jake
      Posted on May 21, 2013 at 17:42 Permalink

      Think I got it. Set the scrollType to “pixels”, set the scrollAmount to “0″. Then let different functions handle the scrolling.

      Reply
  4. Iago
    Posted on May 21, 2013 at 11:57 Permalink

    Hi,

    Thanks for the plugin, but I have a problem with it. When the scroll reaches the end activates the browser’s scroll. Is there any way to lock the browser scroll while the mouse is over the div that has the customScrollbar?

    Kind regards and thanks for your job,
    Iago

    Reply
  5. Janey Smith
    Posted on May 21, 2013 at 08:32 Permalink

    Malihu, awesome script! out of all the other ones on the net, it’s the sleekest looking, finally got it implemented tonight and loving it, many thanks for your work!

    I’m having a bit of a problem (I’m kind of a beginner), wondering if you could shed some light if you have a moment….

    I’m applying the plugin to a div that is hidden/expanded via fadeToggle and every time I click on the link that toggles the div to expand another scroll bar appears until there’s 2,3,4,5…etc scroll bars in the div and they crowd out the content – do you have any idea what might be making this happen?

    A million thank yous for any suggestions :)

    Reply
  6. Peter Reiner
    Posted on May 21, 2013 at 01:11 Permalink

    Hi Malihu – I am just baffled by this problem. Could you take a look at my site http://drumprofessor.net? From the homepage navigation bar, please click on the “testimonials” button. A page that includes your scrollbar will slide into view. Scroll down about halfway until you get to the testimony (text in red) of “Glen G. Gates”. I created two hotspots here, one on his email address, the other for his website. When I click on either hotspot, instead of being taken to the page or email, the scroller takes me halfway up the page again. I’ve tried every variation or trick I can think of. Any idea what I am missing? Thanks very much. from Peter

    Reply
    • Peter Reiner
      Posted on May 21, 2013 at 01:54 Permalink

      solved the problem just now with:

      advanced:{
      autoScrollOnFocus: Boolean
      }

      Thank you!

      Reply
  7. Jorgen
    Posted on May 20, 2013 at 17:49 Permalink

    Hi

    I’ve just downloaded your script and try to make it work. The first thing I’ve noticed is the mousewheel scrolling. It works perfectly when scrolling down, but I cannot scroll up. It works sometimes, but most times it doesn’t.

    My test sample is as simple as can be with a surrounding some simple content. I am testing in IE10, Win8.

    Do you have any ideas of what might be wrong?

    Reply
    • Jorgen
      Posted on May 20, 2013 at 17:52 Permalink

      …and that should be…
      My test sample is as simple as can be with a [div class='scrollbar'] surrounding some simple content.

      Reply
    • Jorgen
      Posted on May 20, 2013 at 17:57 Permalink

      OK, I may have found a bug. Scrolling up with the mousewheel only Works as long as I don’t scroll all the way to the bottom of my content. After hitting the bottom it’s game over for the mousewheel.

      Hope you can replicate and fix it :-)

      Reply
    • Foolish Jorgen
      Posted on May 20, 2013 at 18:13 Permalink

      Don’t worry, it works – my fault of course! :-)

      Reply
      • malihu
        Posted on May 20, 2013 at 19:06 Permalink

        lol @ the name
        No problem :)

        Reply
  8. Krishna Teja Kesineni
    Posted on May 20, 2013 at 15:36 Permalink

    Hi,

    My requirement is that i have to add horizontal and vertical scroll for a same container plz help me in that..

    thanks
    Teja

    Reply
    • malihu
      Posted on May 20, 2013 at 19:08 Permalink

      The plugin currently does not support both axis scrollbars on the same element. I’ll add this feature on the next major version.

      Reply
      • Teja Kesineni
        Posted on May 21, 2013 at 06:57 Permalink

        Do we know when would be the next major release out to the world? Is there any workaround for getting both the scrollbars? We are planning to mimic the code, is it worth doing it? If the this is not possible we may look into another plugin. Please suggest

        Reply
  9. rafal
    Posted on May 20, 2013 at 10:52 Permalink

    Hey There,
    This plugin is great! But i’ve got a little problem.. when resize of my window, can’t use horizontal scroll only vertical.
    Second problem: i’m using scroll bar on my “content” page so when scroll first page to bottom, all others sites opens on bottom. Please help me.
    Btw sorry for my english -.-

    Reply
    • rafal
      Posted on May 21, 2013 at 18:52 Permalink

      please help me

      Reply
  10. Hardy
    Posted on May 19, 2013 at 18:57 Permalink

    $(“#chat_container”).mCustomScrollbar({
    autoHideScrollbar:true,

    scrollButtons:{
    enable:true
    },
    theme:”dark-thick”
    });

    Please…………………….
    How to make this stay on bottom?

    Reply
    • rafal
      Posted on May 21, 2013 at 19:06 Permalink

      horizontalScroll:true;

      Reply
  11. Falk Fiedler
    Posted on May 19, 2013 at 18:29 Permalink

    Hi, thanks for this great plugin.

    Can I also own scroll buttons – outside the scrollable area – use the scroll function and assign them via jquery?

    thank you

    falk

    Reply
  12. Rohan
    Posted on May 19, 2013 at 14:02 Permalink

    I am facing a problem… I have a form inside a wrapper and I called the scroller on wrapper. I worked fine but when I focus on any input field it automatically scrolls back to top. Please help.

    Reply
    • malihu
      Posted on May 19, 2013 at 15:26 Permalink

      This probably happens due to some CSS positioning of input fields being off…
      You can disable auto-scrolling on focus by setting autoScrollOnFocus to false (see Configuration).

      Reply
  13. Alex
    Posted on May 19, 2013 at 10:26 Permalink

    this script is shit. code is too big and incomprehensible !

    for begginers like me it’s just shit !

    why people use this longest script only for scrolling ?!

    Reply
    • malihu
      Posted on May 19, 2013 at 16:04 Permalink

      Hello Alex,

      This script is a plugin, not a tutorial. Its purpose is to plug-it in a project and work. In my opinion, for the amount of features it has and the things you can do with it, its size is not that big.

      People use this plugin because they usually require extra functionality (scroll-to, touch support, nested scrollbars, user defined callback functions etc.) and this script provides them.

      The guides for using and implementing the plugin are fairly simple. If you want to study its source code, you’re more than welcome but the script itself is pretty advanced and not really for beginners in javascript/jQuery (no custom scrollbar script is suited for beginners).

      Thanks for the feedback

      Reply
  14. Peter Reiner
    Posted on May 18, 2013 at 02:58 Permalink

    I’m enjoying your plugin but I’m having trouble when creating hotspots on an image. The page just scrolls upward slowly. If I click very fast, the hotspots work. I must be missing something …

    Reply
  15. Ankit Parikh
    Posted on May 17, 2013 at 14:55 Permalink

    Actually i am applying this scrollbar to a div contained inside body. On page load i set body to display none after 1 sec i set it to display block. But after display block neither my div nor my scrollbar is visible. I tried calling update after the delay but no luck..

    Reply
  16. Devin Walker
    Posted on May 17, 2013 at 00:36 Permalink

    This plugin looks fantastic. I had an issue using it within tabs but figured out how I could initialize the tabs upon each tab control fix. The easing really makes the scrolling super smooth!

    Reply
  17. chandana
    Posted on May 15, 2013 at 14:48 Permalink

    scroll bar appearing fine on page load. but when i click any button in a web page automatically mcustomscrollbar disappears and the default scroll bar get appears. i used scroll bar for datalist item. scroll bar disappear while clicking any item in data list and also getting disapper if i click any other button in a web page. kindly help in resolving this issue.

    Reply
  18. Sylvie
    Posted on May 15, 2013 at 12:29 Permalink

    Hi,
    This is a great plugin and without being an expert, i make it work without problem!
    I just have two questions and one problem.
    Is it possible to make it work with Jquery prettyphoto which dunamically construct an iframe ? I can’t make it works at the moment (using $(“iframe”).mCustomScrollbar({… and even when the iframe as an “id” )…

    But my more urgent problem is to know ik it’s possible to make an element inside the container with the scrollbar, appear in the center of the container space (or go to top).
    I’m using WordPress and I apply the CustomScrollbar to a div which contains a list (ul) with (li) which are dynamically construct by a wordpress loop. This list is placed to the left of the content of the current product browsing. I display all of that on product page, and the list is pretty long… I would have the current element ( which is highlight with css) at the top of the list, is it possible ? Someone could help me on this way, please ?
    I will really appreciate your help, cause i’m lost…
    Many thanks !
    Sylvie

    <script> (function($){ $(window).load(function(){ $("#content-cat-left").mCustomScrollbar({ mouseWheel:true, theme:"dark-thick", scrollButtons:{enable:true, scrollType:"pixels", scrollAmount:200 }, scrollInertia: 0, advanced:{updateOnContentResize: true}, callbacks:{onTotalScrollOffset:100} }); }); })(jQuery); </script> Part of my page <ul id="menu-toggle"> <li <?php if($currentpost == $post->ID) { echo ' class="current"'; } ?>> <div class="show-content-bt"> <?php if( get_field('photo_produit_1') ):?> <div class="photo-prod"> <img src="<?php echo bloginfo('template_url'); ?>/timthumb.php?src=<?php echo get_field('photo_produit_1') ?>&w=57&h=57&zc=1&q=100&a=t" alt="<?php the_title(); ?>" width="57" height="57" alt="<?php the_title(); ?>" /> </div> <?php else: endif;?> <a href="<?php the_permalink(); ?>"><h2><?php the_title(); ?></h2></a> </div> <?php endwhile; ?> <?php wp_reset_postdata(); // reset the query ?> </li> </ul> <!-- End of #menu-toggle -->

    Reply
  19. Daniel S
    Posted on May 14, 2013 at 23:15 Permalink

    Hello Malihu, thank you very much for your plugin. Here’s my question:
    I am having problems making it work with bbq in a div ajax content.
    I tried several ways and I always get different behaviors.
    In this case the first default content loads the scrollbar correctly but following a link and loading ajax content no scrollbar is displayed at all (loaded data exceeds div height).
    Back button works okay but going to the first default page: div#content is hidden

    Thank for help.

    (function($){
    $(window).load(function(){
    $(“#content”).mCustomScrollbar({
    theme:”dark-2″,
    advanced:{
    updateOnContentResize: true
    },
    mouseWheelPixels:300,
    scrollButtons:{
    enable:false,
    scrollSpeed: “auto”
    }
    });
    //$(“#content”).mCustomScrollbar(“update”); //update scrollbar according to newly loaded content
    //$(“#content”).mCustomScrollbar(“scrollTo”,”top”,{scrollInertia:200}); //scroll to top
    });
    })(jQuery);

    $(function(){
    var cache = {
    ”: $(‘.bbq-default’),
    ‘#’:$(‘.bbq-default’)
    };
    $(window).bind( ‘hashchange’, function(e) {
    var url = $.param.fragment();
    $( ‘a.bbq-current’ ).removeClass( ‘bbq-current’ );
    $( ‘#content’ ).children( ‘:visible’ ).hide();
    url && $( ‘a[href="#' + url + '"]‘ ).addClass( ‘bbq-current’ );

    if ( cache[ url ] ) {
    cache[ url ].show();
    }
    else {
    $( ‘.bbq-loading’ ).show();
    cache[ url ] = $( ” )
    .appendTo( ‘#content’ )
    .load( url, function(){
    // Content loaded, hide “loading” content.
    $( ‘.bbq-loading’ ).hide();
    $(“#content”).hide();
    $(“#content”).fadeIn();
    $(“#content”).mCustomScrollbar(“update”);
    //$(“#content”).mCustomScrollbar(“scrollTo”,”top”,{scrollInertia:200});
    });
    }
    })
    $(window).trigger( ‘hashchange’ );
    });

    Reply
  20. Andrea22k
    Posted on May 13, 2013 at 12:13 Permalink

    http://jsfiddle.net/sqfcX/
    could someone help me about this stuff?
    Basically, open your browser console. Then rotate your screen using (CTRL+ALT+LEFT).
    As you can see value in console doesn’t work properly.
    Otherway, removing the scrollbar from #container div fixes the problem.
    But I need the scrollbar on that div. Any solution?
    Thanks

    Reply
  21. Dominic
    Posted on May 12, 2013 at 22:32 Permalink

    Hi there,

    I’m having a really odd problem with embedded Vimeo / Youtube videos

    I get a very fast flickering iframe instead of the embedded video, see here:

    http://andybarter.com/main/?p=409

    The video plays fine when I disable the scroll bar… any ideas?

    Thanks

    Reply
  22. nisan
    Posted on May 12, 2013 at 20:44 Permalink

    Hi,
    first of all great plugin, the best!

    i have a problem, i have two sides in my layout, the left side have scroll and the right side have scroll too.
    when i scroll the left side it scrolls the right side only, and when i scroll the right side it scroll the right side as it should.

    can u help me to understand why it happen plz?

    Reply
  23. Zoran
    Posted on May 10, 2013 at 14:57 Permalink

    Hi,

    I have an issue after calling scrollTo. Problem is that after calling that method a can’t scroll anymore. It looks like it freezes or something like that. Can you help me with that?

    Reply
  24. DrLightman
    Posted on May 10, 2013 at 13:25 Permalink

    Unfortunately, the plugin is *broken* when used toghether with jquery ui:

    http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.9/jquery-ui.min.js

    Muhc of the code seems to execute but the scrollbars stay with display:none;

    Reply
  25. Andrea22k
    Posted on May 10, 2013 at 00:56 Permalink

    Hi malihu. I like your plugin so much. But i found some troubles using max-height. Trying and trying I found what doesn’t work.
    In my website I’m using the box-sizing:border-box property.
    So if my .container has:
    -max-height:500px;
    -padding:20px;
    I can’t see my content when it exceeds 460px and scrollbar doesn’t appear until my content exceeds 500px;
    what can I do?
    Thank you

    Reply
    • Andrea22k
      Posted on May 10, 2013 at 14:32 Permalink

      for now I had to manually subtract 40 in max height calculation in your script. But if you could help with a definitive solution it’d be so much better :)

      Reply
  26. Marco Ghinassi
    Posted on May 9, 2013 at 19:46 Permalink

    Amazing script !!!!
    Really, it is so usefull !! You’ve saved me.

    Reply
  27. michele
    Posted on May 9, 2013 at 18:09 Permalink

    Hi, really great work!
    I use jQuery to display external content in a div and i call mCustomScrollbars function every time i load new content.
    But i am doing saome wrong becouse new content is loaded in a blank page.

    $(document).ready(function() { $('a.lnk1').click(function() { var url = $(this).attr('href'); $('#inferiore-contenuti').fadeOut("slow").hide().load(url).fadeIn("slow",function(){ mCustomScrollbars(); return false; }) }); });

    What am I doing wrong?

    this the page: http://www.michelecurreli.it/mic/tourweaver/pubblicazioni/tour%20dentro%20html/HTML+tour/prova_con_tour/prova%20per%20caricaContenuti+CustomScroller.html

    thanks in advance.

    Reply
    • malihu
      Posted on May 9, 2013 at 18:21 Permalink

      I think you need to prevent the default browser behavior that opens the link URL:
      $(document).ready(function() { $('a.lnk1').click(function(e) { e.preventDefault(); var url = $(this).attr('href'); $('#inferiore-contenuti').fadeOut("slow").hide().load(url).fadeIn("slow",function(){ mCustomScrollbars(); return false; }) }); });

      I’d also suggest using plugin’s update method each time your content changes.

      Reply
      • michele
        Posted on May 9, 2013 at 19:19 Permalink

        Thank’s for your reply.
        Now i can load new content into div but after that mCustomScrollbars doesn’t work.
        I tried to use plugin’s “update”
        I don’t know js very well. What do you think about?

        $(document).ready(function() { $('a.lnk1').click(function(e) { e.preventDefault(); var url = $(this).attr('href'); $('#inferiore-contenuti').fadeOut("slow").hide().load(url).fadeIn("slow",function(){ mCustomScrollbars(),function(){ $(this).mCustomScrollbar("update"); return false; } }) }); });

        I don’t know if it is the riht way.
        Thankyou for any answer.

        page link

        Reply
  28. Chuong
    Posted on May 9, 2013 at 11:25 Permalink

    In a vertical scroller, the scrollbar is on the right side of the content by default. Is there any way to put it on the left side?

    Reply
    • malihu
      Posted on May 9, 2013 at 14:04 Permalink

      The scrollbar styling is done via CSS. Edit jquery.mCustomScrollbar.css and change the properties of .mCustomScrollBox>.mCSB_scrollTools (for placement to the left change right:0 to left:0).

      Reply
  29. Phil
    Posted on May 8, 2013 at 21:43 Permalink

    looks great and is exactly what i need – does it require jQuery 1.9? I got a project where there’s only 1.5 available… sadly no way to upgrade at the moment… did anyone test it with 1.5 ?

    Reply
    • malihu
      Posted on May 8, 2013 at 23:34 Permalink

      It should work fine :)

      Reply
      • Phil
        Posted on May 9, 2013 at 00:16 Permalink

        Just tried it with your Demo-Page (should have thought about this earlier…) and confirm that it works with jQuery 1.5 and 1.7 just as well. :)

        Thanks, great work that saved me a lot of sweat. :)

        Reply
  30. Selim Ozkan
    Posted on May 8, 2013 at 16:37 Permalink

    Hi Malihu,

    Is it possible to scroll two containers together with mCustomScrollbar?

    I willl give some details. I have two divs and everyone holds some text with different languages. I want to scroll in sync this two containers when one of them is scrolled.

    I made this by onScoll event and scrolled the passive one with same percent as the active one is scrolled. Is it a correct way ? Or is there any other simpler way to do this.

    Here is the link of the page : http://www.ozkanyazilim.com/imc/p/ click on the about menu and first picture to get the mentioned page. I can not give the direct link because the page element are coming by an ajax call.

    p.s.: my page is working only in chrome. I couldn’t not resolve this yet :) Any advice is appreciated :)

    Thanks in advance, regards …

    Reply
    • malihu
      Posted on May 8, 2013 at 23:31 Permalink

      If it works, it is the correct way!
      I can’t think of another way to do it. Good thinking :)

      Reply
  31. Krishnan
    Posted on May 8, 2013 at 08:45 Permalink

    Hi,
    I faced a problem when we are using Jquery animate methods like, slideUp, slideDown, animate(), slideToggle the scroll bar not working properly anyone have solution for this??

    Reply
    • malihu
      Posted on May 8, 2013 at 23:27 Permalink

      Check “Important notes” in “Detailed usage guide”. You probably need to call the update method after your animation are completed (or use the updateOnContentResize option parameter).

      Reply
  32. Mikhail
    Posted on May 8, 2013 at 05:43 Permalink

    Malihu,

    Thanks for your great plugin, but I have some problems with it. On one of the pages I used FORM with different inputs. Then I click on text field or text area or search field on the map, it will automatic scroll to top.
    Page with problem
    I don’t understand why it so. Please help :-)

    Thanks.

    P.S. Sorry for my bad English.

    Reply
    • malihu
      Posted on May 8, 2013 at 23:26 Permalink

      Probably some positioning issue with the CSS.
      Set autoScrollOnFocus to false (see Configuration), which disables automatic scrolling when focusing on form fileds.

      Reply
  33. Sina Z
    Posted on May 7, 2013 at 16:42 Permalink

    This is the only working cross-browser scroll I’ve ever seen thanks man. A quick question when I add horizontal scroll bar (horizontalScroll:true), the vertical one gets disabled. Is it normal?

    Reply
    • malihu
      Posted on May 8, 2013 at 23:20 Permalink

      Yes. Both axis scrollbars on the same element is the only feature missing from the plugin. I’ll probably add it on the next major update.

      Reply
  34. Jeff
    Posted on May 7, 2013 at 12:36 Permalink

    Plugin is great, but all users must be AWARE, that they CANNOT!!! use in any projects, where some code is not publicly available, or the will be breaking GNU General Public License v3 license conditions.
    GNU GPL v.3 can be used only! with code licensed by same license.

    In other words, if you use this plugin, I will be able to force you in court of law (if I want to bother) to give me source code of your entire project.

    I would suggest author use GNU LGPL (note leading L) or dual license it under GNU GPL v.3 / MIT

    FYI:
    GNU LGPL protects plugin same as GNU GPL v.3, but allows to use it with code, which is not open source.

    you may take a look here:
    http://en.wikipedia.org/wiki/Comparison_of_free_and_open-source_software_licenses

    Reply
    • malihu
      Posted on May 7, 2013 at 12:47 Permalink

      I think I’ll add MIT license too. Thanks for the info.

      Reply
      • Brian
        Posted on May 8, 2013 at 03:35 Permalink

        +1 for MIT license. Would really like to use this plugin as it is exactly what we need and very well done.

        Currently looking for an alternative as company says we can’t use GPL code.

        Reply
        • malihu
          Posted on May 8, 2013 at 23:16 Permalink

          I’m thinking LGPL also.

          Reply
    • Sina Z
      Posted on May 7, 2013 at 16:48 Permalink

      I’m a bit confused here, in previous comments someone named “Yusef” asked if he can use the plug-in but reference it and Malihu answered “Yeap”. Now here what I’m seeing is we cannot use it in any projects so… :-?

      Thanks for your answer in advance.

      Reply
      • Kouji
        Posted on May 8, 2013 at 00:15 Permalink

        same here, but when i scroll to top i read this on the right blog panel

        Everything published on this blog is free.
        You’re more than welcome to use any plugin, script, template etc. on personal or commercial projects and modify it to suit your needs.

        Reply
      • malihu
        Posted on May 8, 2013 at 23:19 Permalink

        You can use the plugin however you like. The comment above is for some special cases (where code is not publicly available). Anyway, I’ll update the license to cover everything.

        Reply
        • Thomas
          Posted on May 9, 2013 at 01:47 Permalink

          Thanks! That would be cool!

          Reply
      • malihu
        Posted on May 9, 2013 at 16:53 Permalink

        License updated to L-GPL.

        Reply
  35. Christian
    Posted on May 6, 2013 at 18:00 Permalink

    First thanks for your plugin, I’ve been trying to use it in a website I have to make.
    However I’ve been facing a weird issue I can’t resolve.
    The scrollbar doesn’t show up properly unless I press the F12 button to show Firebug… I don’t really understand why the code understands that it doesn’t need the scrollbar
    (I’ve got the noScrollbar class and the scrollTools class as display none until I don’t press F12)
    Is there any chance you could help me ? Thanks :)
    http://img22.imageshack.us/img22/5517/screenshot1le.jpg

    Reply
    • Tom
      Posted on May 8, 2013 at 21:27 Permalink

      I’m having a similar issue. When the page loads the scroll bar isn’t there, but as soon as I re-size the browser window, the scroll bar shows up.
      I tried adding the “update” method after I initialize the scroll bar on my div, but that doesn’t seem to help in this case.

      Reply
      • malihu
        Posted on May 8, 2013 at 23:14 Permalink

        Try setting the updateOnContentResize option parameter to true (auto-calls the update method).

        Reply
        • Tom
          Posted on May 9, 2013 at 23:02 Permalink

          That fixed it. Thanks for the assistance!

          Reply
        • Christian
          Posted on May 11, 2013 at 14:06 Permalink

          That worked for me as well, thank you ! :)

          Reply

Comments pages: 1 10 11 12


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>