admin管理员组文章数量:1419189
I'm working on a webapp that uses CSS3 animations for some nice effects, but I can't figure out to activate them with an onclick
event.
this is the CSS3 Animation: (The name of the DIV this is added to is #smspopup
)
#smspopup {
-webkit-animation: move-sms 1.5s 1;
-webkit-animation-fill-mode: forwards;
}
And this is my Javascript where I just can't figure out what I need to get it going
function cancel_sms()
{
halte.style.opacity = 1;
document.getElementById('smspopup').style.visibility = 'hidden';
document.getElementById('up').style.visibility = 'visible';
}
And another thing I want to do is delay the functions 1.5 seconds until the animation is finished. Anyone any idea?
I'm working on a webapp that uses CSS3 animations for some nice effects, but I can't figure out to activate them with an onclick
event.
this is the CSS3 Animation: (The name of the DIV this is added to is #smspopup
)
#smspopup {
-webkit-animation: move-sms 1.5s 1;
-webkit-animation-fill-mode: forwards;
}
And this is my Javascript where I just can't figure out what I need to get it going
function cancel_sms()
{
halte.style.opacity = 1;
document.getElementById('smspopup').style.visibility = 'hidden';
document.getElementById('up').style.visibility = 'visible';
}
And another thing I want to do is delay the functions 1.5 seconds until the animation is finished. Anyone any idea?
Share Improve this question edited Jul 23, 2021 at 9:21 Brian Tompsett - 汤莱恩 5,89372 gold badges61 silver badges133 bronze badges asked Aug 24, 2012 at 14:31 IanBautersIanBauters 1531 gold badge2 silver badges8 bronze badges 1- This question might help. – Barlas Apaydin Commented Aug 24, 2012 at 14:34
1 Answer
Reset to default 3Starting the animation
Start by using a class instead of an ID. Change the CSS to this:
.smspopup {
-webkit-animation: move-sms 1.5s 1;
-webkit-animation-fill-mode: forwards;
}
And add class=smspopup
to the smspopup
element.
Next, inside the handler (cancel_sms
?), just add the class to the element to begin the animation:
document.getElementById('smspopup').className = 'smspopup';
Animation end callback
For the second question (targeting the end of the animation), there are two options:
Attach a callback to the transitionEnd event. The only problem with this is that you need to listen to vendor-specific events:
myDiv.addEventListener('webkitAnimationEnd', callback);
Use a regular timeout. The problem with this is that the timing won't be perfect (but maybe close enough).
setTimeout(callback, 1500);
本文标签: cssStart CSS3 animation using Javascript with onclick eventStack Overflow
版权声明:本文标题:css - Start CSS3 animation using Javascript with onclick event - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745302089a2652429.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论