【问题标题】:Owl carousel creates extra space at the end猫头鹰旋转木马在最后创造了额外的空间
【发布时间】:2019-03-18 08:48:19
【问题描述】:

当我滑到最后一项时,猫头鹰轮播会在轮播的末端创建一个空白空间。我不确定这是否是默认行为,但对我来说看起来很奇怪。

在此我们可以看到我所说的轮播末尾的额外空间。这是我目前使用的代码:

我正在使用autowidth = true,因为我将为不同的卡片类型(不同的宽度)使用轮播代码...我的问题仅在我滑到最后一项时出现..滑到最后一项时有空位

【问题讨论】:

  • 你能添加你的 html sathya
  • 请为您的代码创建一个代码 sn-p。谢谢
  • 确定..我会更新

标签: css angular owl-carousel


【解决方案1】:

请将项目添加到选项中,

items : 3(您想在屏幕上看到的项目数。)


 $('.owl-carousel').owlCarousel({


      autoWidth:true,
      loop:false,
      items:3,
      center:false,
      dots: false,
      merge:true,
      margin:10,
      lazyload:false,
      nav:true,
      navText: [
        '        <svg class="first" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="62" height="62" viewBox="0 0 62 62"><defs><style>.a1{fill:#fff;stroke:#ec7f4a;stroke-width:4px;}.b1{stroke:#000;}.c1{stroke:none;}.d1{fill:none;}.e1{filter:url(#a1);}</style><filter id="a1" x="0" y="0" width="62" height="62" filterUnits="userSpaceOnUse"><feOffset dy="3" input="SourceAlpha"/><feGaussianBlur stdDeviation="3" result="b"/><feFlood flood-opacity="0.161"/><feComposite operator="in" in2="b"/><feComposite in="SourceGraphic"/></filter></defs><g transform="translate(-1527 -173)"><g class="e1" transform="matrix(1, 0, 0, 1, 1527, 173)"><g class="a1" transform="translate(9 6)"><circle class="c1" cx="22" cy="22" r="22"/><circle class="d1" cx="22" cy="22" r="20"/></g></g><path class="b1" d="M4,11H16.17L10.58,5.41,12,4l8,8-8,8-1.41-1.41L16.17,13H4Z" transform="translate(1570 213) rotate(180)"/></g></svg>',
        '        <svg class="hide-show animate" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="62" height="62" viewBox="0 0 62 62"><defs><style>.a{fill:#fff;stroke:white;stroke-width:4px;}.b{stroke:#000;}.c{stroke:none;}.d{fill:none;}.e{filter:url(#a);}.animate .d,.a{animation: load-icon 1.5s linear .4s ;stroke-dasharray: 200;animation-direction: alternate-reverse;}@keyframes load-icon {to {stroke-dashoffset:200;stroke:#EC7F4A;}}</style><filter id="a" x="0" y="0" width="62" height="62" filterUnits="userSpaceOnUse"><feOffset dy="3" input="SourceAlpha"/><feGaussianBlur stdDeviation="3" result="b"/><feFlood flood-opacity="0.161"/><feComposite operator="in" in2="b"/><feComposite in="SourceGraphic"/></filter></defs><g transform="translate(-11 -173)"><g class="e" transform="matrix(1, 0, 0, 1, 11, 173)"><g class="a" transform="translate(9 6)"><circle class="c" cx="22" cy="22" r="22"/><circle class="d" cx="22" cy="22" r="20"/></g></g><path class="b" d="M20,11H7.83l5.59-5.59L12,4,4,12l8,8,1.41-1.41L7.83,13H20Z" transform="translate(54 213) rotate(-180)"/></g></svg>            '
      ]



  })

谢谢,

【讨论】:

    【解决方案2】:

    通过添加items可以控制显示项。并且还根据您的屏幕宽度使用responsive 控制显示项目。

    下面的例子我已经添加了这样的。希望这对你有用。

    $('.owl-carousel').owlCarousel({		
      loop:false,
      center:false,
      dots: false,
      items:4,
      merge:true,
      margin:10,
      lazyload:false,   
      margin: 10,
      nav:true,
      navText: [
      '<svg class="first" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="62" height="62" viewBox="0 0 62 62"><defs><style>.a1{fill:#fff;stroke:#ec7f4a;stroke-width:4px;}.b1{stroke:#000;}.c1{stroke:none;}.d1{fill:none;}.e1{filter:url(#a1);}</style><filter id="a1" x="0" y="0" width="62" height="62" filterUnits="userSpaceOnUse"><feOffset dy="3" input="SourceAlpha"/><feGaussianBlur stdDeviation="3" result="b"/><feFlood flood-opacity="0.161"/><feComposite operator="in" in2="b"/><feComposite in="SourceGraphic"/></filter></defs><g transform="translate(-1527 -173)"><g class="e1" transform="matrix(1, 0, 0, 1, 1527, 173)"><g class="a1" transform="translate(9 6)"><circle class="c1" cx="22" cy="22" r="22"/><circle class="d1" cx="22" cy="22" r="20"/></g></g><path class="b1" d="M4,11H16.17L10.58,5.41,12,4l8,8-8,8-1.41-1.41L16.17,13H4Z" transform="translate(1570 213) rotate(180)"/></g></svg>',
      '<svg class="hide-show animate" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="62" height="62" viewBox="0 0 62 62"><defs><style>.a{fill:#fff;stroke:white;stroke-width:4px;}.b{stroke:#000;}.c{stroke:none;}.d{fill:none;}.e{filter:url(#a);}.animate .d,.a{animation: load-icon 1.5s linear .4s ;stroke-dasharray: 200;animation-direction: alternate-reverse;}@keyframes load-icon {to {stroke-dashoffset:200;stroke:#EC7F4A;}}</style><filter id="a" x="0" y="0" width="62" height="62" filterUnits="userSpaceOnUse"><feOffset dy="3" input="SourceAlpha"/><feGaussianBlur stdDeviation="3" result="b"/><feFlood flood-opacity="0.161"/><feComposite operator="in" in2="b"/><feComposite in="SourceGraphic"/></filter></defs><g transform="translate(-11 -173)"><g class="e" transform="matrix(1, 0, 0, 1, 11, 173)"><g class="a" transform="translate(9 6)"><circle class="c" cx="22" cy="22" r="22"/><circle class="d" cx="22" cy="22" r="20"/></g></g><path class="b" d="M20,11H7.83l5.59-5.59L12,4,4,12l8,8,1.41-1.41L7.83,13H20Z" transform="translate(54 213) rotate(-180)"/></g></svg>            '
      ],
      autoplay: true,
      autoplayHoverPause: true,
      responsive: {
        0: {
        items: 2
        },
        767: {
        items: 3
        },
        1024: {
        items: 4
        }
      }
    });
    <link href="https://cdnjs.cloudflare.com/ajax/libs/OwlCarousel2/2.3.4/assets/owl.carousel.min.css" rel="stylesheet"/>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/OwlCarousel2/2.3.4/owl.carousel.min.js"></script>
    <div class="carousel-wrap">
        <div class="owl-carousel">
            <div class="item"><img src="http://placehold.it/150x150"></div>
            <div class="item"><img src="http://placehold.it/150x150"></div>
            <div class="item"><img src="http://placehold.it/150x150"></div>
            <div class="item"><img src="http://placehold.it/150x150"></div>
            <div class="item"><img src="http://placehold.it/150x150"></div>
            <div class="item"><img src="http://placehold.it/150x150"></div>
        </div>
    </div>

    【讨论】:

    • 抱歉忘了提这个..我使用 autowidth = true 因为我将使用不同卡片类型(不同宽度)的轮播代码...我的问题仅在我滑到最后一个时出现item..当滑动到最后一个 item 时有一个空格
    • 您必须使用小提琴链接更新完整代码,然后只有我们知道主要问题。
    • 我在这个codepen中完全复制了同样的错误..codepen.io/anon/pen/ZPRajx
    • 是的,sathya。您必须使用responsive 来控制项目并在没有空格的情况下扩展项目宽度。
    • 当您滑到旋转木马的末端时,您会看到一些空白区域。感谢您的帮助!
    猜你喜欢
    • 1970-01-01
    • 2019-08-14
    • 2022-06-28
    • 1970-01-01
    • 1970-01-01
    • 2021-10-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多