运行结果尺寸: 300 x 150
x
 
<!DOCTYPE html>
<html>
<head>
<style> 
div {
  width: 100px;
  height: 100px;
  background: red;
  position: relative;
  animation: mymove 2s infinite;
}
@keyframes mymove {
  from {left: 0px;}
  to {left: 200px;}
}
@keyframes myNEWmove {
  from {width: 0px;}
  to {width: 500px; background: blue;}
}
</style>
</head>
<body>
<h1>使用 JavaScript 更改动画名称</h1>
<p>单击“试一试”按钮更改动画中使用的@keyframes:</p>
<button onclick="myFunction()">试一试</button>
<div id="myDIV"></div>
<p><strong>注意:</strong> animationName 属性在 Internet Explorer 9 及更早版本中不受支持。</p>
<script>
function myFunction() {
  document.getElementById("myDIV").style.animationName = "myNEWmove";
}
</script>
</body>
</html>
×

报个问题: