如何从 owl-carousel 2 中删除项目? [英] How to remove an item from owl-carousel 2?

查看:78
本文介绍了如何从 owl-carousel 2 中删除项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从猫头鹰轮播库中删除项目?

这是我的 html 标记:

这是我的 JavaScript:

$(".owl-carousel").owlCarousel({项目:1,保证金:10,rtl:对,自动高度:真,懒加载:真});

解决方案

根据 Owl Carousel 文档 您可以按如下方式删除索引,但是 Owl Carousel 2 目前处于测试版,请确保将来检查文档以获得更好的方法(如果他们曾经实施):

var indexToRemove = 2;$(".owl-carousel").trigger('remove.owl.carousel', [indexToRemove]).trigger('refresh.owl.carousel');

根据评论,如果它对您不起作用,请尝试以下操作:

var owlCarousel = jQuery(".owl-carousel").data('owlCarousel');owlCarousel.removeItem(1);

How can I remove an item from an owl carousel gallery?

Here's my html markup:

<div class="owl-carousel owl-theme">
    <img src="/assets/storage/gallery/1.jpg"></div>
    <img src="/assets/storage/gallery/2.jpg"></div>
    <img src="/assets/storage/gallery/3.jpg"></div>
    <img src="/assets/storage/gallery/4.jpg"></div>
</div>

And here's my JavaScript:

$(".owl-carousel").owlCarousel({
  items: 1,
  margin: 10,
  rtl: true,
  autoHeight: true,
  lazyLoad: true
});

解决方案

according to Owl Carousel Documentation you can remove an index as following, however Owl Carousel 2 is in beta version right now, make sure to check docs in future for better ways (if they ever implement):

var indexToRemove = 2;
$(".owl-carousel").trigger('remove.owl.carousel', [indexToRemove]).trigger('refresh.owl.carousel');

according to a comment, if it didn't work for you try the following:

var owlCarousel = jQuery(".owl-carousel").data('owlCarousel');
owlCarousel.removeItem(1);

这篇关于如何从 owl-carousel 2 中删除项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆