css动画完成后运行js脚本

Sai*_*ent 6 javascript css asp.net

我正在使用此代码创建移动文本的动画我 ASP.NET Core 项目 http://www.html.am/html-codes/marquees/css-scrolling-text.cfm 如何在动画后执行 js sctipt完成了吗?类似的东西,我想在动画完成后刷新页面

    <script>
       function myFunction() {
           location.reload();
       }
    </script>
Run Code Online (Sandbox Code Playgroud)

Bra*_*xon 5

您真正需要做的就是创建一个 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!";
});
Run Code Online (Sandbox Code Playgroud)
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);
  }
}
Run Code Online (Sandbox Code Playgroud)
<p id='change'>
This text will change when the animation has ended.
</p>
<circle></circle>
Run Code Online (Sandbox Code Playgroud)