猫头鹰轮播-仅用一个点滑动多个轮播

时间:2018-07-23 03:02:24

标签: javascript jquery owl-carousel owl-carousel-2

我有两个想使用的轮播,它们都具有相同数量的物品,所以可以,但是我只想进行一次导航dots并能够触发多个{{1} }具有相同的属性。

dots

第一个功能是获取所有猫头鹰点并添加$('.div_main .owl-dots').each(function(index) { $(this).attr('data-index','dot-'+index); }); $('.owl-dots[data-index="dot-0"] button').each(function(index) { $(this).attr('data-index','dot-'+index); }); $('.owl-dots[data-index="dot-1"] button').each(function(index) { $(this).attr('data-index','dot-'+index); }); $('.div_main .owl-dot').click(function(e) { e.preventDefault(); var idx = $(this).data('index'); $('.div_main').each(function() { $(this).find('button.owl-dot').eq(0).attr('data-index',idx).click(); }); }); 属性以了解哪个。第二个和第三个是使它们相同的方法,例如如果这个index具有button,而另一个data-index="dot-0"也将是owl.dots,那么这次,我要么想触发其中一个并生病,只是找到具有相同button[data-index="dot-0"]的另一个button,但这会导致错误。

data-index

我认为我的第四个功能有问题。或者是否存在某个实例,一个 Uncaught RangeError: Maximum call stack size exceeded 会通过dots触发另一个dots

1 个答案:

答案 0 :(得分:1)

此点击处理程序:

$('.div_main .owl-dot').click(function(e) {
  e.preventDefault();

  if(!$(this).is(".active"){
   var idx = $(this).data('index');
   $("[data-index='"+idx+"']").not(this).click();
  }
});

注意.not(this)

您有此错误,基本上是因为您在说:«单击我,请单击我。»...这会导致最大堆栈错误。

因此,还要检查该点是否已激活将停止无限循环。

相关问题