run()函数里的if语句的条件报错了:
Uncaught TypeError: Cannot read properties of undefined (reading 'style')
请问如何修改才能让i变量可以在if里起作用?
var ulpainshop = document.querySelectorAll('.ulpainshop');
var opacity = 0;
//二级菜单持续显示
console.log("js已执行");
function screenmove(){
console.log("鼠标移入执行");
var i = 0;
}
//通用的文字出现动画
function textAnimationStart(name){
this.name = name;
console.log("动画已执行");
var i =0;
name[i].style.visibility = "visible";
while(i<3){
console.log("a步骤");
var timer = null;
timer = setInterval(run,20);
name[i].style.opacity = opacity;
function run(){
if (name[i].style.opacity == 1) { /*这里的style报错了,我手动把i换成0的时候就不会报错*/
console.log("结束");
clearInterval(timer);
} else {
console.log("c步骤");
opacity = opacity + 0.05;
}
}
i++;
}
}