如何添加悬停暂停(jquery)
代码如下:如何添加悬停暂停(jquery),jquery,Jquery,代码如下: $(document).ready(function(){ $('#testimonials .slide'); setInterval(function(){ $('#testimonials .slide').filter(':visible').fadeOut(1000,function(){ if($(this).next('li.slide').size()){ $(this).n
$(document).ready(function(){
$('#testimonials .slide');
setInterval(function(){
$('#testimonials .slide').filter(':visible').fadeOut(1000,function(){
if($(this).next('li.slide').size()){
$(this).next().fadeIn(2000);
}
else{
$('#testimonials .slide').eq(0).fadeIn(2000);
}
});
},1000);
});
这适用于ul列表,并希望在悬停时添加暂停。有什么建议吗 您需要保存由
setInterval
返回的对象,然后您可以将其传递到clearInterval
,以阻止其再次发生
以下是一些示例代码,这些代码应该让您了解您所追求的:
$(document).ready(function(){
var slider = function() {
$('#testimonials .slide').filter(':visible').fadeOut(1000,function(){
if($(this).next('li.slide').size()){
$(this).next().fadeIn(2000);
}
else{
$('#testimonials .slide').eq(0).fadeIn(2000);
}
});
};
// save an object so that I can start and stop this as we go
var interval = setInterval(slider, 1000);
// when the user hovers in, clear the interval; if they hover out,
// restart it again
$('#testimonials .slide').hover(function() {
clearInterval(interval);
}, function() {
interval = setInterval(slider, 1000);
});
});
请注意,我不清楚用户悬停在什么位置以使间隔停止,因此我假设您希望
$(“#推荐.slide”)
这样做。如果没有,只需将该部分更改为您需要的内容。您所说的“暂停”是什么意思?你能给我们举个例子吗?我已经搜索了一段时间了。我找错东西了。我很高兴我找到了这个!请您协助: