使用JavaScript从/到参数设置webkit - 关键帧 [英] Set the webkit-keyframes from/to parameter with JavaScript

查看:188
本文介绍了使用JavaScript从/到参数设置webkit - 关键帧的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么方法可以使用JavaScript来设置webkit-keyframe的从或吗?

Is there any way to set the from or to of a webkit-keyframe with JavaScript?

推荐答案

各种解决方案:

var cssAnimation = document.createElement('style');
cssAnimation.type = 'text/css';
var rules = document.createTextNode('@-webkit-keyframes slider {'+
'from { left:100px; }'+
'80% { left:150px; }'+
'90% { left:160px; }'+
'to { left:150px; }'+
'}');
cssAnimation.appendChild(rules);
document.getElementsByTagName("head")[0].appendChild(cssAnimation);

只是在标题中添加了样式定义。

Just adds a style definition to the header. Would be much cleaner/better to define it though the DOM if possible.

编辑:Chrome使用旧方法时出错

Error in Chrome with old method

这篇关于使用JavaScript从/到参数设置webkit - 关键帧的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆