![](/img/trans.png)
[英]Is it possible to prevent the Bootstrap carousel pause on mouse hover and continue automatically cycling?
[英]How can I pause a Bootstrap Carousel on hover and resume it on mouse-out?
我的网站上有一个Bootstrap Carousel。
当用户将鼠标悬停在元素#formcontainer
,我想暂停旋转木马。 当我徘徊时,我想继续旋转木马的循环。 第一部分可以正常使用以下代码,但不是第二部分。 有人可以帮忙吗?
$(document).ready(function() {
$('.carousel').carousel({
interval: 1200,
pause: "hover"
});
$('#formcontainer').hover(function(){
$("#myCarousel4").carousel('pause');
});
});
在mouseleave
事件上使用轮播cycle
方法
$('#formcontainer').hover(function(){
$("#myCarousel4").carousel('pause');
},function(){
$("#myCarousel4").carousel('cycle');
});
jQuery的悬停功能有这两个参数的实现 : 在处理悬停和悬停出处理程序:
$('#foo').hover(function() {
// handler in
}, function() {
// handler out
});
当你通过它只是一个说法 ,你给它的功能处理和退出事件双方 ,所以你要暂停其在两个鼠标输入和鼠标了。
你需要传递它单独的处理程序:
$('#myCarousel4').hover(function() {
$(this).carousel('pause');
}, function() {
$(this).carousel('cycle');
});
请注意,我们可以使用this
来引用轮播而不是重写其ID。 在jQuery事件处理程序中, this
总是指在可能的情况下绑定事件的对象。
这会奏效!
(function($) {
$(document).ready(function(){
$('.carousel').carousel({
pause: 'hover'
});
}); }(jQuery));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.