简体   繁体   English

如何区分自动滑动和单击滑动Bootstrap传送带?

[英]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.

相关问题 在 angular 中路由返回时,引导轮播不会自动滑动? - Bootstrap Carousel does not auto-slide when routing back in angular? 引导轮播(自动滑动不起作用) - bootstrap carousel (auto-slide doesn't work) 如何使用rails视图内容(不是图像)自动滑动主页轮播 - How to auto-slide the homepage carousel with rails views content (not images) 如何停止移动设备中的轮播自动滑动? - How to stop carousel auto-slide in mobile devices only? 有没有办法获取自动幻灯片 w3 轮播的当前幻灯片编号? - Is there a way to get current slide number of an auto-slide w3 carousel? Bootstrap Carousel:移除自动滑动 - Bootstrap Carousel : Remove auto slide 自定义JQuery滑块(自动滑动) - Custom JQuery Slider (auto-slide) 如何使Bootstrap Carousel从单击按钮的第一张幻灯片开始? - How to make Bootstrap Carousel to start from the first slide on button click? 如何转到leftChevron上的特定幻灯片,而不是直接进入上一张幻灯片,请点击自举轮播? - how to go to specific slide on leftChevron click in bootstrap carousel instead of going to immediate previous slide? 当 TextInput 有焦点时,如何将窗口从键盘后面自动滑出? - How to auto-slide the window out from behind keyboard when TextInput has focus?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM