[英]How to differentiate between auto-slide and click slide Bootstrap carousel?
I have carousel control buttons that I am adding an active
class to when a new slide is selected. 我有轮播控制按钮,在选择新幻灯片时,我要向其中添加
active
类。
This is a simple task when someone clicks on one of these buttons, but if I want to incorporate autoplay
, this suddenly becomes much more challenging. 当有人单击这些按钮之一时,这是一个简单的任务,但是如果我想合并
autoplay
,这突然变得更具挑战性。
Here is the problem: 这是问题所在:
I can bind slid
to a function that adds the active class to my control buttons, and it will be functional, BUT there will be a delay between the start of the slide and the addition of the active class, because slid
is fired when the slide is complete. 我可以绑定
slid
至,增加了活动类,以我的控制按钮的功能,这将是功能性的,但会有幻灯片,添加活动类的开始之间的延迟,因为slid
就会引发滑动完成了。
Fortunately, Bootstrap provides slide
, which is fired when a slide is initiated. 幸运的是,Bootstrap提供了
slide
,当启动幻灯片时会触发该幻灯片。 I could bind slide
to a function that adds the active class to the next slide in the list, but then this would cause problems when I try to click a control button for a slide that is out of order. 我可以将
slide
绑定到一个将活动类添加到列表中下一张slide
的函数上,但是当我尝试单击不正确的幻灯片的控制按钮时,这会导致问题。
slide
is fired whenever a slide happens, so if someone clicks on a control button that is not in the normal slide order, I will end up with two active buttons. slide
会在每次发生幻灯片时触发,因此,如果有人单击了不在正常幻灯片顺序中的控制按钮,我将得到两个活动按钮。
The only solution I can see currently, is to somehow differentiate between a slide
event that is automatically triggered, and one that is triggered by a click. 我目前可以看到的唯一解决方案是,以某种方式区分自动触发的
slide
事件和单击触发的事件。
Any ideas? 有任何想法吗?
Try this: 尝试这个:
$('.carousel').carousel({
interval: 2000
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.