【问题标题】:How to position Owl Carousel so that item in center always fits the framed image?如何定位 Owl Carousel 以使中心的项目始终适合框架图像?
【发布时间】:2021-01-25 22:08:53
【问题描述】:

如何定位框架以使中心项目始终适合其中?无论一行中有多少项。

我不确定为什么 sn-p 不起作用,这里也是 Codepen https://codepen.io/ivan-topi/pen/LYRKvpJ

$('.owl-carousel').owlCarousel({
  loop: true,
  margin: 10,
  nav: true,
  autoplay: true,
  responsive: {
    0: {
      items: 1
    },
    600: {
      items: 3
    },
    1000: {
      items: 6
    }
  }
})
.container {
  margin: 90px auto;
  max-width: 1600px;
  position: relative;
  padding: 0 15px;
}

.frame {
  position: absolute; 
  top: -80px;
  left: 50%; 
  transform: translateX(-50%);
  width: 240px;
  opacity: .55;
  z-index: 10;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.2/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/OwlCarousel2/2.1.3/owl.carousel.min.js"></script>

<div class="container">
  <img class="frame" src="https://www.pngfind.com/pngs/m/103-1034073_html-file-mobile-frame-download-free-hd-png.png"/>
  <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 class="item"><img src="http://placehold.it/150x150"></div>
  </div>
</div>

【问题讨论】:

    标签: jquery css owl-carousel


    【解决方案1】:

    您必须将center: true 属性设置为owlCarousel 对象。

    $('.owl-carousel').owlCarousel({
      loop: true,
      margin: 10,
      nav: true,
      center: true,
      autoplay: true,
      responsive: {
      0: {
        items: 1
      },
      600: {
        items: 3
      },
      1000: {
        items: 6
      }
    }
    

    })

    【讨论】:

    • 也许我误会了你。我以为您要求将活动轮播框架居中对齐。在您的示例中,活动框架适合移动窗口的一半。
    • 啊,我没注意到区别。玩了之后好像可以用了,谢谢! codepen.io/ivan-topi/pen/LYRKopY
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-07-23
    • 2018-06-07
    • 1970-01-01
    • 2019-01-18
    • 2017-01-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多