js里的for循环控制不住了,代码如下 20
for(vary=0;y<9;y++){vartimr=setInterval(function(){varnew_lef=img10.style.left;varne=...
for(var y=0;y<9;y++) {
var timr = setInterval(function(){
var new_lef = img10.style.left;
var ne = parseInt(new_lef)+60;
// 获得旧值
var o_left = img9.style.left;
// 计算新值
var n_left = parseInt(o_left)+1;
// 将新值赋值回
img9.style.left = n_left+'px';
if (img9.style.left==ne+'px') {
i++;
img9.src = 'img/Plants/PeaBulletHit.gif';
img10.style.opacity = 0.5;
setTimeout(function(){
img9.src = 'img/Plants/PB00.gif';
img10.style.opacity = 1;
img9.style.left = 0;
},100);
// 停止定时器
clearInterval(timr);
}
if (i==8) {
img11.style.display = 'block';
img10.src = 'img/Zombies/Zombie/ZombieLostHead.gif'
img11.style.left = img10.style.left;
setTimeout(function(){
img10.src = 'img/Zombies/Zombie/ZombieDie.gif';
clearInterval(tie);
img8.style.display = 'none';
setTimeout(function(){
img10.style.display = 'none';
},3000)
},3000)
setTimeout(function(){
img11.style.display = 'none';
},1500)
}
if (i==10&&img9.style.left==800+'px') {
img9.style.left = 0;
}
},10);
} 展开
var timr = setInterval(function(){
var new_lef = img10.style.left;
var ne = parseInt(new_lef)+60;
// 获得旧值
var o_left = img9.style.left;
// 计算新值
var n_left = parseInt(o_left)+1;
// 将新值赋值回
img9.style.left = n_left+'px';
if (img9.style.left==ne+'px') {
i++;
img9.src = 'img/Plants/PeaBulletHit.gif';
img10.style.opacity = 0.5;
setTimeout(function(){
img9.src = 'img/Plants/PB00.gif';
img10.style.opacity = 1;
img9.style.left = 0;
},100);
// 停止定时器
clearInterval(timr);
}
if (i==8) {
img11.style.display = 'block';
img10.src = 'img/Zombies/Zombie/ZombieLostHead.gif'
img11.style.left = img10.style.left;
setTimeout(function(){
img10.src = 'img/Zombies/Zombie/ZombieDie.gif';
clearInterval(tie);
img8.style.display = 'none';
setTimeout(function(){
img10.style.display = 'none';
},3000)
},3000)
setTimeout(function(){
img11.style.display = 'none';
},1500)
}
if (i==10&&img9.style.left==800+'px') {
img9.style.left = 0;
}
},10);
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询