i am experiencing strange issue with OWL CAROUSEL 2. I'm creating simple carousel for 12 tables, but when using option "autoWidth", last table is pulled out from carousel stack.
DEMO
If you open fiddle, there is carousel for every month in year. At the end of carousel, there is no December, but if you check source code, you can see that December is there. For some reason OWL carousel plugin is pulling December out.
Any ideas? In advance, many thanks!
if you want : Always show 1 element : you should set width of owl-item is 100% and width of owl-carousel is : 100% . Or always show 2,3,4,5,.... you should set width of owl-item is (100/2) %, (100/3)%, (100/4)%, ... Corresponding with screen will show 4 for desktop, 1 for mobile :you show use breakpoint to set width.
Add the Javascript codes that make the Owl Carousel work to the field after the <body></body> tags are closed. Note: These codes also work when added to any area of the page, but adding <script></script> codes to the bottom of the page will be more advantageous in terms of site speed.
In order to stop owl auto play you can trigger the corresponding event: stop. owl.
Use transitionStyle option to set transtion. There are four predefined transitions: "fade" , "backSlide" , goDown and scaleUp . You can also build your own transition styles easily. For example by adding "YourName" value transitionStyle: "YourName" , owlCarousel will add .
Add just display flex in CSS for .owl-stage
class and also add jS function for smaller devices.
CSS
.owl-stage{display:flex}
JS
$('.owl-carousel').owlCarousel({
loop: false,
autoWidth:true,
margin:10,
nav:true,
responsive:{
0:{
items:1,
autoWidth:false
},
768:{
items:3
}
}
});
I just ran into this issue too.
I fixed it in a bad way, but it is working. in both browsers.
The problem was with the owl-stage
element. The owl carousel lib counted the width property, but the items doesn't fit in the wrapper.
So I have to call a function after the init
event happened and add about 100px
to it.
I used the setTimeout function with this .Very bad approach I know, but in my project there are a lot of js functions happening and not allways get the right width
property (sometimes i get undefined
)
So the code is:
$('.owl-carousel').owlCarousel({
margin:90,
nav:true,
dots:true,
autoWidth:true,
afterInit: setWidth()
});
function setWidth(){
setTimeout(function(){
var carWidth = $('.owl-stage').width() + 100;
$('.owl-stage').width(carWidth);
},200);
}
I'm sure it could work without setTimeout
, but deadlines can't wait
(*feeling bad for it).
Hope it helps!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With