js动态设置多个@keyframes,动画加载宽度

在这里插入图片描述
效果如上

const list = [
  {name: '小五', num: 50  },   {name: '大三', num: 30  }
]

$.each(list, function (i, item) {
       const animationName = `animation${i}`;
       const keyframes = `@keyframes ${animationName} {
           0% { width: 0 } 
           100% { width: ${item.num}%; }
       }`;
       const style = document.createElement('style');
       style.innerHTML = keyframes;
       document.head.appendChild(style);
       const animation = `${animationName} 1s ease forwards`

      <div class="exercise-progress exercise-progress${i}" style="width: ${item.num};animation: ${animation}"></div>
}

相关推荐

  1. 停止css @keyframes动画

    2024-03-26 03:28:02       58 阅读
  2. 登录动画

    2024-03-26 03:28:02       69 阅读
  3. Ionic 动画

    2024-03-26 03:28:02       25 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-03-26 03:28:02       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-03-26 03:28:02       100 阅读
  3. 在Django里面运行非项目文件

    2024-03-26 03:28:02       82 阅读
  4. Python语言-面向对象

    2024-03-26 03:28:02       91 阅读

热门阅读

  1. 逻辑门与或非门的工艺结构原理及选型参数总结

    2024-03-26 03:28:02       51 阅读
  2. Python的条件语句与循环语句的语法

    2024-03-26 03:28:02       43 阅读
  3. C++ 中的 unordered_map 用法文档

    2024-03-26 03:28:02       47 阅读
  4. Elasticsearch(15) multi_match的使用

    2024-03-26 03:28:02       45 阅读
  5. 剑指offer面试题40 数组中只出现一次的数字

    2024-03-26 03:28:02       48 阅读
  6. anaconda配置虚拟python环境

    2024-03-26 03:28:02       44 阅读
  7. 速盾:免备案防攻击cdn

    2024-03-26 03:28:02       39 阅读
  8. Shell脚本总结-read-case语句

    2024-03-26 03:28:02       44 阅读
  9. 突破编程_C++_面试(STL 编程 queue)

    2024-03-26 03:28:02       35 阅读
  10. 数据结构-栈-004

    2024-03-26 03:28:02       42 阅读