Sam Skirrow
Sam Skirrow

Reputation: 3697

Owl Carousel css set to display:none when page has loaded

I'm having an issue with my Owl Carousel on my page. Currently, the carousel container and items don't display. Iused my web inspector to check the element and it appears that it has the line display:none in the css. However, when I change this to display:block, the items show one under the other, rather than in a line horizontally.

My script for the carousel is as follows:

jQuery(function($){
    $('.owl-carousel').owlCarousel({
        loop:true,
        margin:10,
        nav:true,
        dots:true,
        autoplay:true,
        autoplayHoverPause:true,
        items:4,
        responsive:{
          0:{
            items:1
          },
            480:{
        items:2
          },
            768 :{
        items:4  
          }
        }
    })
});

My HTML markup is as follows:

<div class="row owl-carousel container">
    <div id="layers-widget-carousel-5-931" class="item layers-widget-carousel-931">
    ...
    </div>
    <div id="layers-widget-carousel-5-715" class="item layers-widget-carousel-715">
    ...
    </div>
    <div id="layers-widget-carousel-5-95" class="item layers-widget-carousel-95">
    ...
    </div>

I have the scripts owl.carousel.min.js, owl.carousel.css and owl.theme.default.css loaded in the head (didn't work when loaded in the footer either).

Is there any obvious reason why this might not be working?

Upvotes: 5

Views: 20243

Answers (8)

M Shahzeb Raza
M Shahzeb Raza

Reputation: 63

Just add the scripts in the head tag instead of putting them at the end of body tag!

Upvotes: 0

OctaviaLo
OctaviaLo

Reputation: 1396

If you are calling owlCarousel() in a function, make sure the document is ready first. Example .js file:


(function ($) {
  function initOwlCarousel() {
    $('.owl-carousel').owlCarousel();
  }

  $(document).ready(function () {
    initOwlCarousel();
  });
})(jQuery);


Upvotes: 0

Shawn Stolting
Shawn Stolting

Reputation: 1

Guys i found the solution. Your jquery file needs to be above your owl javascript file. That easy.

Just make sure your jquery is above everything cause it needs to be executed first.

Upvotes: -1

icortesi
icortesi

Reputation: 760

I was having this issue and it was because I forgot to add the js call at the end.

$(document).ready(function(){
  $(".owl-carousel").owlCarousel();
});

Upvotes: 7

!!!Attention!!!

If u have this problem all u should do to solve it is to replace owl library before your scripts. Example:

<footer>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="js/owl.carousel.min.js"></script>
<!-- here goes your scripts -->
<script src="js/main.js"></script>
</footer>

Upvotes: 2

A.N.
A.N.

Reputation: 51

With version 1.3.3 I had the same problem. I didn't see the carousel, because items had "display:none" in CSS. When I changed "display:none" into "display:block" I could see the items, but as a column.

I discovered, that the link to owl.carousel.js was in a wrong place, in the header. I moved it to the footer, and it solved the problem.

Upvotes: 3

zloctb
zloctb

Reputation: 11184

only added for container display:none and carusel added display:block himself

Upvotes: 0

Aadil P.
Aadil P.

Reputation: 150

Hi I was in the same spot as you. I searched and searched and ended up here.

Just out of curiosity I updated the JS and CSS to the latest version. So that worked for me.

However, I also found this - Link to Github item

Hope this helps.

Upvotes: 0

Related Questions