Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
460 views
in Technique[技术] by (71.8m points)

jquery - How to position Owl Carousel so that item in center always fits the framed image?

How can I position frame so that center item always fits inside of it? No matter how many items are in a row.

I am not sure why the snippet isn't working, here is Codepen as well 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>
question from:https://stackoverflow.com/questions/65893100/how-to-position-owl-carousel-so-that-item-in-center-always-fits-the-framed-image

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You have to set the center: true property to owlCarousel object.

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

})


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...