我在div块中收集了图像
我想以一段时间逐个隐藏它们。
我试过这个剧本。
$(document).ready(function () {
delayInSeconds = 1;
i = 0;
setInterval(function () {
while (i < 10) {
$(".images").eq(i).hide();
i++;
}
}, delayInSeconds * 50);
});
答案 0 :(得分:0)
这是因为第一次迭代开始时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
...
答案 1 :(得分:0)
$(document).ready(function () {
$(".images").each(function(){
setTimeOut($(this).hide(),300);
});
});
这应该这样做。 希望这会对你有所帮助
答案 2 :(得分:0)
这样做。它使用:visible
选择器来丢弃隐藏的图像,:eq(0)
选择器从匹配集中获取单个元素。
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();
});