【问题标题】:Run js script after css animation is finishedcss动画完成后运行js脚本
【发布时间】:2018-11-17 10:08:52
【问题描述】:
【问题讨论】:
标签:
javascript
css
asp.net
【解决方案1】:
您真正需要做的就是创建一个 Javascript 事件监听器:
下面的示例为圆形对象创建了一个事件侦听器。您可以运行该示例来实时查看它。
另外,所有的 CSS / circle 的东西都只是动画,你真正需要看的是 javascript 部分。
var circle = document.getElementsByTagName("circle")[0];
var change = document.getElementById("change");
circle.addEventListener("animationend", function() {
change.innerHTML = "The animation has ended!";
});
circle {
border-radius: 50%;
width: 100px;
height: 100px;
background-color: rgba(0,0,255,0.9);
border: 2px solid black;
position: absolute;
animation: bounce 1.5s;
animation-direction: alternate;
animation-timing-function: cubic-bezier(.5,0.05,1,.5);
animation-fill-mode: forwards;
}
@keyframes bounce {
from {
transform: translate3d(0, 0, 0);
}
to {
transform: translate3d(0, 200px, 0);
}
}
<p id='change'>
This text will change when the animation has ended.
</p>
<circle></circle>