暂停使用jQuery生成的无限循环
我使用的是根据我的需要稍加修改的:暂停使用jQuery生成的无限循环,jquery,animation,loops,Jquery,Animation,Loops,我使用的是根据我的需要稍加修改的: $(document).ready(function() { var NewsRotator = {init: function() { var numberOfTitles = $('.NewsRotator li').length; //set current item var currentTitle = 0; //show first item $('.NewsRotator li').eq(currentTit
$(document).ready(function() {
var NewsRotator = {init: function()
{
var numberOfTitles = $('.NewsRotator li').length;
//set current item
var currentTitle = 0;
//show first item
$('.NewsRotator li').eq(currentTitle).fadeIn(1000); //initial fade-in
//loop through the items
var infiniteLoop = setInterval(function(){
$('.NewsRotator li').eq(currentTitle).fadeOut(100); //current item fade-out time
if(currentTitle == numberOfTitles -1){
currentTitle = 0;
}else{
currentTitle++;
}
$('.NewsRotator li').eq(currentTitle).fadeIn(900); //next item fade-in time
}, 3000); //interval between items
}
};
NewsRotator.init();
});
下面是一个关于
我想做的是在鼠标上方设置动画暂停,并在鼠标离开时继续
谢谢大家! 实现这一点有两种方法:
true
有两种方法可以实现这一点:
true
下面是将全局标志设置为暂停并在悬停时播放的方法,以及
另外-我认为可以通过缓存“li”选择器稍微提高性能。下面是设置全局标志以暂停并在悬停时播放的方法,以及一个
另外-我认为可以通过缓存'li'选择器稍微提高性能。看看这个,下面是暂停和恢复计时器的答案。这里有更多的常见问题解答,我希望这将帮助您获得更多想法看看这个,这里是暂停和恢复计时器的答案。这里有更多可用的常见问题解答,我希望这将帮助您获得更多想法您不能暂停时间间隔,但可以清除它,然后重新启动。您不能暂停时间间隔,但可以清除它,然后重新启动。
var NewsRotator = (function(){
var numberOfTitles = $('.NewsRotator li').length,
currentTitle = 0;
return {
flag : true,
init : function(){
$('.NewsRotator').on({
mouseenter : function(){
NewsRotator.flag = false;
},
mouseleave : function(){
NewsRotator.flag = true;
}
});
$('.NewsRotator li').eq(currentTitle).fadeIn(1000);
infiniteLoop = setInterval(function () {
if (NewsRotator.flag == true){
$('.NewsRotator li').eq(currentTitle).fadeOut(100);
if (currentTitle == numberOfTitles - 1) {
currentTitle = 0;
} else {
currentTitle++;
}
$('.NewsRotator li').eq(currentTitle).fadeIn(900);
} else {
return false;
}
}, 3000);
}
};
}());
$(document).ready(function(){
NewsRotator.init();
});