Owl carousel not displayed

谁说胖子不能爱 提交于 2019-12-11 18:52:47

问题


I'm trying to use OwlCarousel version 2.0 together with Bootstrap 3 and Meteor.

I create a template for the carousel like this:

<template name="featuredCarousel">
<div class = "row">
    <div class="owl-carousel">
        <div class="item"><h4>1</h4></div>
        <div class="item"><h4>2</h4></div>
        <div class="item"><h4>3</h4></div>
    </div>
</div>
</template>

I include this in my index.html file:

<div class="container">
    {{> featuredCarousel}}
</div>

Finally, I have a separate .js-file for instantiating the carousel:

$('.owl-carousel').owlCarousel({
loop:true
});

This code is largely copied from the documentation. Therefore, I would expect it to work. However, it simply displays nothing. The carousel seems to be the problem here, because when I remove the .owl-carousel class from the div, the elements are displayed (though not in a carousel of course).

Can anyone tell me why this is not working and how to get it working? I would really appreciate your help.

Thanks,

Tony


回答1:


You need to put the instantiation code inside a rendered callback:

Template.featuredCarousel.rendered = function() {
  $('.owl-carousel').owlCarousel({
   loop:true
  });
}


来源:https://stackoverflow.com/questions/25334574/owl-carousel-not-displayed

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!