OWL Carousel 2宽度不正确,显示所有项目

时间:2015-12-02 14:59:18

标签: javascript css owl-carousel

我有以下OWL Carousel 2初始化代码:

  $(document).ready(function(){
            moment.locale('nl-NL');

            $("#owl-slider").owlCarousel({ 
              items: 1,
              responsive: false,
              nav : false,
              loop: false,
              dots: true,                  
              dotsEach: 1,
              autoplaySpeed : 300,
              dotsSpeed : 400,
              autoPlay: true,
              navRewind: true,
              animateOut: 'fadeOut'
            });

        });

这会产生以下旋转木马的html:

  <div class="item-list" id="newsblock">
    <div id="owl-slider" class="owl-carousel owl-theme owl-loaded">
        <div class="owl-stage-outer">
            <div class="owl-stage" style="transform: translate3d(-934px, 0px, 0px); transition: 0s; width: 1401px;">
                <div class="owl-item" style="width: 467px; margin-right: 0px;">
                    <div class="item">
                        <img width="100%" src="/SITES/FOCUS-DEV/NIEUWS/PUBLISHINGIMAGES/INKTPOT.PNG?RenditionID=5" data-themekey="#">
                        <div class="header">
                            <h2 class="title">
                                <a title="Nieuwsbericht" href="https://testprorail.sharepoint.com/sites/Focus-DEV/nieuws/Paginas/Nieuwsbericht.aspx" rel="bookmark">Nieuwsbericht</a>
                            </h2>
                            <div class="time">17 November</div>
                        </div>
                    </div>
                </div><div class="owl-item" style="width: 467px; margin-right: 0px;">
                    <div class="item">
                        <img width="100%" src="/SITES/FOCUS-DEV/NIEUWS/PUBLISHINGIMAGES/8628PEPERNOTEN-550X485.JPG?RenditionID=5" data-themekey="#">
                        <div class="header">
                            <h2 class="title">
                                <a title="Nog meer nieuws" href="https://testprorail.sharepoint.com/sites/Focus-DEV/nieuws/Paginas/Nog-meer-nieuws.aspx" rel="bookmark">Nog meer nieuws</a>
                            </h2>
                            <div class="time">17 November</div>
                        </div>
                    </div>
                </div>
                <div class="owl-item active" style="width: 467px; margin-right: 0px;">
                    <div class="item">
                        <img width="100%" src="/SITES/FOCUS-DEV/NIEUWS/PUBLISHINGIMAGES/INKTPOT.PNG?RenditionID=5" data-themekey="#">
                        <div class="header">
                            <h2 class="title">
                                <a title="Test" href="https://testprorail.sharepoint.com/sites/Focus-DEV/nieuws/Paginas/test.aspx" rel="bookmark">Test</a>
                            </h2>
                            <div class="time">17 November</div>
                        </div>
                    </div>
                </div>
            </div>
        </div><div class="owl-controls">
            <div class="owl-nav">
                <div class="owl-prev" style="display: none;">prev</div>
                <div class="owl-next" style="display: none;">next</div>
            </div>
            <div class="owl-dots" style="">
                <div class="owl-dot"><span></span></div>
                <div class="owl-dot"><span></span></div>
                <div class="owl-dot active"><span></span></div>
            </div>
        </div>
    </div>
</div>

问题是,owl-stage div的宽度设置为所有三个项目的宽度,而不是1.所有项目都显示而不是1.

请提供一些可能解决方案的指导!

亲切的问候。

3 个答案:

答案 0 :(得分:0)

为你的javascript添加singleItem:true。

这将使它一次只显示一个图像。

答案 1 :(得分:0)

我通过将此代码添加到CSS解决了我的问题:

.owl-item {
  float: left;
}
.owl-carousel {
  overflow: hidden;
}

答案 2 :(得分:-1)

owl stage div的宽度将始终延伸到父级轮播容器(div id =&#34; owl-slider&#34; class =&#34; owl-carousel owl-theme&#34;)是旋转木马中不止一个项目。通过在CSS中设置overflow to hidden,可以很容易地解决这个问题。

.owl-carousel {
   overflow: hidden;
}