perfect-scrollbar icon indicating copy to clipboard operation
perfect-scrollbar copied to clipboard

getInstance function

Open kkaplita opened this issue 7 years ago • 5 comments

I would like to get instances of PerfectScrollbar by select element. In my project perfect scrollbar is initialized in many views and I want to get all instances in mainView to update etc.

kkaplita avatar Apr 14 '18 07:04 kkaplita

You could also manage your own collection of instances as you create them.

GufNZ avatar May 08 '18 22:05 GufNZ

I would also be interested in this feature. Some libraries create the scrollbar themselves, so we cannot control, for example, the options. :slightly_frowning_face:

It can be something like: $el.data("jq.PerfectScrollbar")

Or something like: $el.PerfectScrollbar

I would also enjoy a way to override the options, especially the "handlers", but if I have the instance, I can always destroy and create another.

DarkCompiled avatar Oct 06 '19 18:10 DarkCompiled

Bump .. I have the same requirement for this

f135ta avatar Feb 01 '20 14:02 f135ta

I'm using JQuery, and i've been able to solve this using the JQuery caching feature.

const ps = new PerfectScrollbar(elementName,
{
    wheelSpeed: 0.2,
    swipeEasing: true,
    wheelPropagation: propagateScrolling,
    minScrollbarLength: 20,
    maxScrollbarLength: 150
});

// Store the Perfect Scrollbar Instance for later
$(elementName).data("ps-" + elementName, ps);

Then in my "update" method, I just fetch the instance from the cache and call ".update" like this

var ps = $(elementName).data("ps-" + elementName);
if (ps !== null) {
     ps.update();
}

@DarkCompiled - I dont think it'll help with your problem of not being able to get to instances created by third parties though..

f135ta avatar Feb 01 '20 16:02 f135ta

We have the same requirement, but this issue is open for a long time. Is it not going to happen?

ferrykranenburgcw avatar Jul 14 '21 06:07 ferrykranenburgcw