【发布时间】:2015-03-31 18:40:51
【问题描述】:
我的 html 中有一个闪烁的红色框,它使用 css 动画。我希望能够将它从闪烁的红色和白色变为绿色和白色。我知道这可以通过使用 getElementbyId 在 id 元素上完成,但是如何访问 css 中的绿色氨基化框。 红框是这样的:
@-webkit-keyframes 'noConnection'
{
1% { background-color: red; }
33% { background: white; }
66% { background: red; }
100% { background: white; }
}
绿色是这样的:
@-webkit-keyframes 'Connection'
{
1% { background-color: green; }
33% { background: white; }
66% { background: green; }
100% { background: white; }
}
动画如下所示:
#animate {
height: 15px;
width: 15px;
}
.cssanimations #animate {
-webkit-animation-direction: normal;
-webkit-animation-duration: 5s;
-webkit-animation-iteration-count: infinite;
-webkit-animation-name: Connection;
-webkit-animation-timing-function: ease;
我认为我必须从 javascript 更改属性 -webkit-animation-name: 才能执行此操作,但我不知道如何处理它来更改它。
还是创建一个重复的 #animate 并使用 getElementById 重命名它会更好?
【问题讨论】:
-
也许
$('#animate').css('-webkit-animation-name','noConnection');(因为您使用的是jQuery)有效?不过不确定。 -
效果很好
标签: javascript jquery html css animation