javascript - 使用 React 在循环中更改路径
问题描述
我想用循环改变javascript中的样式。在 Vanilla js 中,这有效:
for(let i=1; i<13; i++){
const path1 = document.querySelector(".path"+i);
path1.style.animation = "animate 1.4s forwards";
}
但现在我尝试学习 React,但我很难达到同样的效果。我使用参考:
startpath1 = createRef();
for(let i=1; i<13; i++){
this.startpath1.current.style.animation = "animate 1.4s forwards";
}
此代码有效,但我如何在此处更改“startpath1”,例如 startpath + 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);
}
推荐阅读
- c - GCC 输出空的汇编文件
- php - Parsing a Multi Dimensional JSON string from URL
- python - 为什么元素的形状和逻辑索引数组似乎会转置维度?
- c++ - 运算符 << 依赖于参数的查找不在全局命名空间中查找
- r - 当数据有效时,R Shiny validate 返回错误
- google-contacts-api - Google People API 不会更新 Person/UserDefined
- reactjs - 每个 React 组件的 Console.log 按钮功能
- amazon-web-services - 如何根据网站用户在 S3 上添加非公开网站文件?
- sql - 基于不同的字段值在 R 中创建子集数据集
- php - 使用 WooCommerce 会员资格时,Wordpress 强制 the_content() 返回完成