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

相关文章:

  • 2021-08-15
  • 2021-11-03
  • 2021-11-28
  • 2021-10-19
  • 2021-12-28
  • 2021-12-23
  • 2021-12-05
  • 2021-12-21
猜你喜欢
  • 2021-12-06
  • 2021-11-02
  • 2021-10-15
  • 2021-12-04
  • 2021-12-06
  • 2021-11-28
  • 2021-09-25
  • 2021-08-15
相关资源
相似解决方案