动态管理 webkit 动画
我正在寻找一种无需部署静态 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我发现 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.