Search code examples
jqueryjscrollpanebrowser-scrollbars

How can I inititalise jScrollPane only when an element has an overflow scrollbar?


I have some ul elements with overflow: auto. Most of them don't overflow but a few of them do. I want to initialise jScrollPane only on those elements that have overflow, that have a scrollbar.

I can't see an obvious way in the docs to do this!

Perhaps I need to detect the presence of a scrollbar in some other way and then nest my jScrollPane initialisation inside that?


Solution

  • You can check if the contents of the ul element is bigger than the display size of the ul with the following code:

    $(yourobject).attr('scrollHeight') > $(yourobject).height() 
    

    You can use the jQuery filter operation to filter your query.