Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Owl carousel - auto width, last item is pulled out from stack

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!

like image 901
SirInfant Avatar asked Jan 09 '15 15:01

SirInfant


People also ask

How do you repair the width of an owl carousel?

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.

How do you make an owl carousel responsive?

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.

How do you turn off auto slide on owl carousel?

In order to stop owl auto play you can trigger the corresponding event: stop. owl.

How do you add transitions to owl Carousel?

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 .


2 Answers

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
    }
   } 
 });  
like image 161
Ishvar Akhaja Avatar answered Nov 15 '22 06:11

Ishvar Akhaja


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!

like image 37
cs.matyi Avatar answered Nov 15 '22 05:11

cs.matyi