Style animationName 属性
改变 <div> 元素的 animationName 属性:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>蜜蜂教程(mifengjc.com)</title>
<style>
div {
width: 100px;
height: 100px;
background: red;
position: relative;
animation: mymove 2s infinite;
/*Safari 和 Chrome*/
-webkit-animation: mymove 2s infinite;
}
@keyframes mymove {
from {
left: 0px;
}
to {
left: 200px;
}
}
@-webkit-keyframes mymove {
/*Safari 和 Chrome*/
from {
left: 0px;
}
to {
left: 200px;
}
}
@keyframes myNEWmove {
from {
width: 0px;
}
to {
width: 500px;
background: blue;
}
}
@-webkit-keyframes myNEWmove {
/*Safari 和 Chrome*/
from {
width: 0px;
}
to {
width: 500px;
background: blue;
}
}
</style>
</head>
<body>
<p>点击“尝试一下”按钮改变动画中要使用的关键帧:</p>
<button onclick="myFunction()">尝试一下</button>
<script>
function myFunction() {
document.getElementById("myDIV").style.animationName = "myNEWmove";
document.getElementById("myDIV").style.WebkitAnimationName = "myNEWmove"; // 针对 Chrome 和 Safari 的代码
}
</script>
<p><strong>注意:</strong>Internet Explorer 9 及其之前的版本不支持 animationName 属性。</p>
<div id="myDIV"></div>
</body>
</html>
定义和用法
animationName 属性设置或返回 @keyframes 动画的名称。
浏览器支持
Internet Explorer 10、Firefox 和 Opera 支持 animationName 属性。
Safari 和 Chrome 支持另一个可替代该属性的属性,即 WebkitAnimationName 属性。
注意:Internet Explorer 9 及其之前的版本不支持 animationName 属性。
语法
返回 animationName 属性:
object.style.animationName
设置 animationName 属性:
object.style.animationName = "none|keyframename|initial|inherit"
属性值
值 | 描述 |
---|---|
none | 默认值。规定没有动画(可用于重写来自级联的动画)。 |
keyframename | 规定要绑定到选择器的关键帧的名称。 |
initial | 设置该属性为它的默认值。请参阅 initial。 |
inherit | 从父元素继承该属性。请参阅 inherit。 |
技术细节
默认值: | none |
---|---|
返回值: | 字符串,表示元素的 animation-name 属性。 |
CSS 版本 | CSS3 |
相关文章
CSS 参考手册:animation-name 属性