var style = document.createElement('style');
style.type = 'text/css';
style.innerHTML = 'body{color:red;}/*你要插入的样式*/';
document.getElementsByTagName('head')[0].appendChild(style);

简单介绍原理就是重新插入一段css样式,达到创建keyframes的目的。

另外还有利用 document.stylesheet.insertRule的方法去做,不过没调试出来,这里贴个 MDN介绍的方法。

https://developer.mozilla.org/zh-CN/docs/Web/API/CSSStyleSheet/insertRule

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-01-17
  • 2022-12-23
猜你喜欢
  • 2022-01-25
  • 2021-11-03
  • 2021-07-17
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-01
相关资源
相似解决方案