Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jScrollPane resize

Tags:

jquery

I have a div which has 100% width of the window, which is a container for the jScrollPane div.

When the window resizes, the scroll pane does not move. Is there any way to make jScrollPane resize with the window?

Thanks!

like image 825
ewd Avatar asked Aug 21 '10 12:08

ewd


People also ask

How do you set bounds of JScrollPane?

The bounds come down to the position and size of the component. The best way to change the size of a scroll pane is to change the size of the component it is displaying. A text area can be resized by setting the number of rows & columns (easily specified in the constructor), or by setting a different font size.

What is the difference between JScrollPane and JScrollBar?

A JScrollBar is a component and it doesn't handle its own events whereas a JScrollPane is a Container and it handles its own events and performs its own scrolling.

How do I make JScrollPane transparent?

You need to use setOpaque(false) to make it transparent. Call that both on the JScrollPane, and on it's ViewPort. sp. setOpaque(false); sp.


2 Answers

You can use the API call reinitialise() to do this. It is covered in one of the example pages here. http://jscrollpane.kelvinluck.com/dynamic_height.html
http://jscrollpane.kelvinluck.com/dynamic_width.html

$(function()
{
$('.scroll-pane').each(
    function()
    {
        $(this).jScrollPane(
            {
                showArrows: $(this).is('.arrow')
            }
        );
        var api = $(this).data('jsp');
        var throttleTimeout;
        $(window).bind(
            'resize',
            function()
            {
                if ($.browser.msie) {
                    // IE fires multiple resize events while you are dragging the browser window which
                    // causes it to crash if you try to update the scrollpane on every one. So we need
                    // to throttle it to fire a maximum of once every 50 milliseconds...
                    if (!throttleTimeout) {
                        throttleTimeout = setTimeout(
                            function()
                            {
                                api.reinitialise();
                                throttleTimeout = null;
                            },
                            50
                        );
                    }
                } else {
                    api.reinitialise();
                }
            }
        );
    }
)

});
like image 191
Alex Avatar answered Sep 22 '22 06:09

Alex


I prefer something like this:

$(window).resize(function(){
    $.each( $('.scrollcont'), function(){
            var api = $(this).data('jsp');
            api.reinitialise();
    });
});

Where '.scrollcont' is the scroll container.

This script is usefull also if u have to resize the size of the scroll container during the action.

like image 34
Dtnand Avatar answered Sep 25 '22 06:09

Dtnand