如何使用JavaScript onClick播放CSS动画?我目前有:
.classname {
-webkit-animation-name: cssAnimation;
-webkit-animation-duration:3s;
-webkit-animation-iteration-count: 1;
-webkit-animation-timing-function: ease;
-webkit-animation-fill-mode: forwards;
}
@-webkit-keyframes cssAnimation {
from {
-webkit-transform: rotate(0deg) scale(1) skew(0deg) translate(100px);
}
to {
-webkit-transform: rotate(0deg) scale(2) skew(0deg) translate(100px);
}
}
如何申请onClick?
发布于 2011-01-31 23:34:18
你确定你只在webkit上显示你的页面吗?这是在safari中传递的代码。单击按钮后,图像(id='img')
将旋转。
function ani() {
document.getElementById('img').className = 'classname';
}
.classname {
-webkit-animation-name: cssAnimation;
-webkit-animation-duration: 3s;
-webkit-animation-iteration-count: 1;
-webkit-animation-timing-function: ease;
-webkit-animation-fill-mode: forwards;
}
@-webkit-keyframes cssAnimation {
from {
-webkit-transform: rotate(0deg) scale(1) skew(0deg) translate(100px);
}
to {
-webkit-transform: rotate(0deg) scale(2) skew(0deg) translate(100px);
}
}
<input name="" type="button" onclick="ani()" value="Click">
<img id="img" src="https://i.stack.imgur.com/vghKS.png" width="328" height="328" />
发布于 2011-01-31 14:17:47
您只需使用:active
pseudo-class即可。这是在单击任何元素时设置的。
.classname:active {
/* animation css */
}
发布于 2011-01-31 14:12:17
您可以通过绑定onclick侦听器,然后像这样添加animate类来实现这一点:
$('#button').onClick(function(){
$('#target_element').addClass('animate_class_name');
});
https://stackoverflow.com/questions/4847996
复制相似问题