Javascript 清爽猫头鹰旋转木马 2

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/32347919/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 07:56:09  来源:igfitidea点击:

Refreshing Owl Carousel 2

javascriptjqueryeventtriggerowl-carousel-2

提问by vedran

I have 3 divs that activate slide toggle when I click on them. And inside every div there is owl carousel slider.

我有 3 个 div,当我点击它们时会激活幻灯片切换。在每个 div 内都有 owl carousel 滑块。

If I trigger one div the slider shows, but when I click other div slider doesn't show unless I resize the window.

如果我触发一个 div,滑块会显示,但是当我单击其他 div 滑块时,除非我调整窗口大小,否则它不会显示。

How can I trigger refresh on slide toggle for the slider in every div?

如何在每个 div 中的滑块的滑动切换上触发刷新?

I tried with this on slide toggle but it doesn't work:

我在幻灯片切换上尝试过这个,但它不起作用:

$('.owl-slider').trigger('refresh.owl.carousel');

回答by egvrcn

You trigger with a class. You can try with a variable:

你用一个类触发。您可以尝试使用变量:

var $owl = $('.owl-carousel').owlCarousel({
    items: 1,
    loop:true
});

$owl.trigger('refresh.owl.carousel');

回答by Moaaid Jamal

if .trigger('refresh.owl.carousel');didn't work with you, you can use

如果.trigger('refresh.owl.carousel');不适合你,你可以使用

window.dispatchEvent(new Event('resize'));

window.dispatchEvent(new Event('resize'));

which will make the carousel refresh automatically.

这将使轮播自动刷新。