Javascript 使用React更改循环中的路径

Javascript 使用React更改循环中的路径,javascript,reactjs,loops,for-loop,styles,Javascript,Reactjs,Loops,For Loop,Styles,我想用循环更改javascript中的样式。在这种情况下: for(let i=1; i<13; i++){ const path1 = document.querySelector(".path"+i); path1.style.animation = "animate 1.4s forwards"; } for(设i=1;ifunction sleep(毫秒){ 返回新承诺(resolve=>setTimeout(resolve,ms));

我想用循环更改javascript中的样式。在这种情况下:

for(let i=1; i<13; i++){
const path1 = document.querySelector(".path"+i);
 path1.style.animation = "animate 1.4s forwards";
}
for(设i=1;i
function sleep(毫秒){
返回新承诺(resolve=>setTimeout(resolve,ms));
}
const demo=async()=>{
等待睡眠(100);
如果(就绪1){
对于(设i=1;i
函数睡眠(ms){
返回新承诺(resolve=>setTimeout(resolve,ms));
}
const demo=async()=>{
等待睡眠(100);
如果(就绪1){

对于(假设i=1;i在数组中插入startpath就足够了

const tab = [this.startpath0, this.startpath1]
for(let i=0; i<13; i++){
            tab[i].current.style.animation = "animate 1.4s forwards";
            await sleep(200);
        }
const选项卡=[this.startpath0,this.startpath1]

对于(设i=0;i在数组中插入startpath就足够了

const tab = [this.startpath0, this.startpath1]
for(let i=0; i<13; i++){
            tab[i].current.style.animation = "animate 1.4s forwards";
            await sleep(200);
        }
const选项卡=[this.startpath0,this.startpath1]

对于(假设i=0;在第一个示例中,
const
是块范围的,每次迭代都会创建一个新变量,保存不同DOM元素的值。要使用
ref
,同样需要将
ref
附加到每个JSX元素。我不确定上下文,但附加一个条件cla添加相应样式的ss将更加简单。直接使用dom元素不是一种反应方式。您应该将动画作为道具传递,并在jsx渲染中使用它。在第一个示例中,
const
是块范围的,每次迭代都会创建一个新变量,保存不同dom元素的值ent.要使用
ref
,您同样需要将
ref
附加到每个JSX元素。我不确定上下文,但附加一个添加相应样式的条件类会更简单。直接使用dom元素不是一种反应方式。您应该将动画作为一个道具,并在jsx渲染中使用它。
const tab = [this.startpath0, this.startpath1]
for(let i=0; i<13; i++){
            tab[i].current.style.animation = "animate 1.4s forwards";
            await sleep(200);
        }