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

Post a comment

Comments pages: 1 14 15 16

  1. 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
  2. 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
  3. 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
  4. 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
  5. 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
  6. 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
  7. 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
  8. 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
  9. 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
  10. 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
  11. 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
  12. Chris
    Posted on July 18, 2014 at 13:08 Permalink

    This an amazing plugin, thank you :)

    Reply
  13. 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
  14. 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
  15. 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
  16. 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
  17. 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
  18. 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
  19. 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
  20. 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
  21. IşıkFX
    Posted on July 1, 2014 at 14:31 Permalink

    Thank for post !

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

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

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

    sfdsfdsfdsfdsf

    Reply
  24. 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
  25. 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
  26. 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
  27. 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