Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery custom content scroller not display when div have parameter hide

I have jQuery custom content scroller on my website inside of a div. The div content has the parameter ("#content").hide(). The div is visible when the page loads and the jQuery custom content scroller works perfectly.

But if the div content is not visible when the page loads, the jQuery custom content scroller is not visible and does not work. I noticed that when you shrink or enlarge the window, the scroller displays. I have small example on this URL: http://www.frantatoulen.wz.cz/

Where might the problem be?

like image 674
user1871954 Avatar asked Dec 03 '12 09:12

user1871954


1 Answers

The problem is that when #content is hidden, the plugin script cannot calculate content length (hidden element has zero dimensions). Because of that, the script assumes that content does not need a scrollbar.

Solution A:

You need to call the update method of the plugin after your content toggles and becomes visible (plugin homepage has info and examples on using methods and parameters). Inside your click function, add the following at the end:

$("#tlacitko").click(function(){
    $("#content").toggle();
    $("#content").mCustomScrollbar("update");
});

Note: The scrollbar does work when you resize the browser because it auto-calls the update method on window resize event.

Solution B:

You can simply set the updateOnContentResize option parameter to true. This auto-calls the update method each time your content length changes:

$("#content").mCustomScrollbar({
    advanced:{
        updateOnContentResize:true
    }
});
like image 108
malihu Avatar answered Nov 15 '22 08:11

malihu