【问题标题】:Run js script after css animation is finishedcss动画完成后运行js脚本
【发布时间】:2018-11-17 10:08:52
【问题描述】:

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

    <script>
       function myFunction() {
           location.reload();
       }
    </script>

【问题讨论】:

标签: 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>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-11
    • 2014-01-22
    相关资源
    最近更新 更多