I've got a dozen galleries and some of them only has one image. This is causing the carousel and page to break because the carousel has loop = true
set on it. I'm trying to write a condition to say if there's more than one item in the carousel, to make loop = true
else make loop = false
. However, I took a shot at it but it doesn't seem to be working.
$(".mbgc-gallery").owlCarousel({
margin: 0,
dots: false,
nav:($(".mbgc-gallery .owl-item").length > 1) ? true: false,
navText: [],
loop:($(".mbgc-gallery .owl-item").length > 1) ? true: false,
autoplay: false,
autoplayHoverPause: true,
responsive: {
0: {
items: 1
},
600: {
items: 1
},
1000: {
items: 1
}
}
});
Can it work like this or do I need to do something after it initializes?
EDIT
I forgot to mention that a page could have more than one gallery on it, so I am not sure if this needs to be wrapped in a .each
function or maybe a unique selector? I have data attributes set up on each gallery so it has an unique ID.