I have a page with multiple sliders that are created with owl carousel. I would like to define different number of visible items for each slider. The perfect solution would be to define number of visible items in HTML (as a class or data). I am just starting using jQuery so I only managed to pass a value using data attribute like this:
<div class="owl-carousel" data-itemsnumber="5">...</div>
Then I applied this value to a variable in JS and add this variable in settings instead of items number like this.
var slides = $('.owl-carousel').data('itemsnumber');
$(".owl-carousel").owlCarousel(
{
items: slides
});
The above code is not working properly as value from first slider is applied to all sliders on page, and I need each of them to have different number of items. How can I achieve this?
Thanks in advance
There are some pre-defined options defined in owl-carousels:
You could use the above options to set how many items would be shown according to the screen width. some what like this:
Also if you are using the carousels for images, then images might overlap at different screens. so you could make the width of images 100% in your css file.
The css for Owl Carousel (for version 1 -- I haven't used 2 in production) is .owl-carousel and .owl-theme (added by the script). Since I have shared styles among all sliders and specific styles for other sliders, I use .owl-carousel OR just the class name since
.owl-controls
are not shared by any other style anywhere else. I can just style .owl-controls if they are global to all my sliders. If you need to style different controls for different sliders you would be more specific with your CSS such as.myfunky-slider .owl-controls {}
.I use .owl-carousel on the html with my own class for that slider:
I use jQuery to call them by my class name:
I style them with shared and specific styles based on shared or specific class names:
i found this as best solution hope it helps,