动态管理 webkit 动画

发布于 2024-12-05 05:30:51 字数 556 浏览 1 评论 0原文

我正在寻找一种无需部署静态 CSS 声明即可管理 webkit 动画的好方法。简而言之,仅使用 Javascript 添加关键帧部分、删除它们、更改它们等。我想我可以问而不是重新发明轮子。

是否有一个简单的 javascript 库可以执行类似的操作(不是 jQuery 或类似的东西,只是一小段函数)?

必须有一种方法可以做这样的事情(伪代码):

function setupAnim(aName) {
 /* becomes: @-webkit-keyframes "aName" */
 var mRule = jsAddCSSRule(aName);
 if (mRule) {
   /* inject CSS properties here */
   mRule.innerHTML = "from {...} to {...}";
 }
}

function removeAnim(aName) {
  var mRule = jsFindCSSRule(aName);
  if (mRule) {
    removeCSSRule(mRule);
  }
}

欢迎任何帮助!

I am looking for a good way to manage webkit animations without deploying a static CSS declaration. In short, adding keyframe sections, removing them, altering them etc. using Javascript only. I figured I could ask instead of reinventing the wheel.

Is there a simple javascript lib out there that does something like this (not jQuery or anything like that, just a small snippet of functions )?

There has to be a way to do something like this (pseudo code):

function setupAnim(aName) {
 /* becomes: @-webkit-keyframes "aName" */
 var mRule = jsAddCSSRule(aName);
 if (mRule) {
   /* inject CSS properties here */
   mRule.innerHTML = "from {...} to {...}";
 }
}

function removeAnim(aName) {
  var mRule = jsFindCSSRule(aName);
  if (mRule) {
    removeCSSRule(mRule);
  }
}

Any help is welcome!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

娇女薄笑 2024-12-12 05:30:51

我发现 https://github.com/krazyjakee/keyframes.js 它允许您创建和覆盖 CSS 动画。然而,它(目前)破坏了单个

将来,CSSOM提案的实现可能会让我们做出更细粒度的改变。 https://github.com/NV/CSSOM

在浏览器控制台中查看,我确实发现浏览器暴露了操纵现有 CSS 规则的方法,但我并没有取得很大的成功。

I found https://github.com/krazyjakee/keyframes.js which allows you to create and overwrite CSS animations. However it (currently) clobbers a single <style> element, which might be inefficient if you are creating a lot of animation rules, because the browser has to re-parse all of them.

In the future, implementations of the CSSOM proposal may let us make more fine-grained changes. https://github.com/NV/CSSOM

Poking around in the browser console, I did find browsers exposing methods for manipulating existing CSS rules, but I did not have a lot of success with them.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文