Hi, nice plugin.
I have two questions:
documentation does not specify that 芯ptions can be set through in data attributes ( Example: data-simplebar-autohide="false" ) Can you add information about that?
now simplebar inited only by ID ( new SimpleBar(document.getElementById('myElement')) or new SimpleBar($('#myElement')[0]) ) can you make init it by class name? Example:
new SimpleBar($('.js-simplebar'), {
option1: value1,
option2: value2
})
Thanks for your attention.
Hi,
good point for the data attribute! I'll add it to the doc.
About your second point, yes, you can init Simplebar as you want, it simply takes an element as input.
The problem on your example is that you pass it a jQuery object and not directly a DOM element. If I remember well, in jQuery you can do $('.js-simplebar').get(0) to get the DOM element from a jQuery object.
If you don't want to use jQuery for that, you can do document.getElementsByClassName('js-simplebar')[0].
@Grsmto Hi! Can i init like that ?
new SimpleBar( document.getElementsByClassName('js-simplebar') )
so i want to pass a list of elements
No you have to pass a single element. So you'll have to loop through every elements selected and initialise Simplebar for each of them. Something like:
Array.prototype.forEach.call(document.getElementsByClassName('js-simplebar'), function(el) {
new SimpleBar(el);
});
Or if you use jQuery:
$('.js-simplebar').each(function(el) {
new SimpleBar(el);
});
@Grsmto thanks
@Grsmto thanks
@Grsmto thanks
$('.js-simplebar').each(function(index, el) {
new SimpleBar(el);
});
Most helpful comment
@Grsmto thanks