Jquery 以一定的时间间隔逐个隐藏图像集合
我有一个div块中的图像集合 我想隔一段时间把它们一个一个地藏起来 我试着用这个脚本Jquery 以一定的时间间隔逐个隐藏图像集合,jquery,Jquery,我有一个div块中的图像集合 我想隔一段时间把它们一个一个地藏起来 我试着用这个脚本 $(document).ready(function () { delayInSeconds = 1; i = 0; setInterval(function () { while (i < 10) { $(".images").eq(i).hide(); i++; } }, delayInSe
$(document).ready(function () {
delayInSeconds = 1;
i = 0;
setInterval(function () {
while (i < 10) {
$(".images").eq(i).hide();
i++;
}
}, delayInSeconds * 50);
});
$(文档).ready(函数(){
延迟时间=1;
i=0;
setInterval(函数(){
而(i<10){
$(“.images”).eq(i).hide();
i++;
}
},延迟数*50);
});
这是因为当第一次迭代开始时,i
的值为10
解决这个问题的一个办法是:
...
function hideOne(i) {
$(".images").eq(i).hide();
if($(".images").eq(i+1).length > 0) { // or change to if(i+1 < 10) if you're sure
setTimeout(function() {
hideOne(i+1);
}, delayInSeconds * 1000); // given the variable name, the multiplier should be 1000, i believe
}
}
hideOne(0); // start it
...
。。。
函数hideOne(i){
$(“.images”).eq(i).hide();
if($(“.images”).eq(i+1).length>0{//,如果您确定,请更改为if(i+1<10)
setTimeout(函数(){
希多内(i+1);
},delayUnseconds*1000);//给定变量名,我相信乘数应该是1000
}
}
hideOne(0);//开始吧
...
这应该可以做到。
希望这对你有帮助这就行了。它使用
:visible
选择器放弃隐藏图像,使用:eq(0)
选择器从匹配集中获取单个元素
你能告诉我要对我的集装箱做什么改动吗
$(document).ready(function () {
$(".images").each(function(){
setTimeOut($(this).hide(),300);
});
});
var delayInSeconds = 1;
function hide(){
setTimeout(function(){
var images = $('.images:visible:eq(0)');
if(images.length == 1){
images.hide();
hide();
}
}, 1000 * delayInSeconds);
}
$(document).ready(function(){
hide();
});