最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Run js script after css animation is finished - Stack Overflow

programmeradmin5浏览0评论

I`m using this code to create an animation of moving text i ASP.NET Core project .cfm How do I execute js sctipt after animation is finished? Something like that, I want to refresh page after animation is finished

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

I`m using this code to create an animation of moving text i ASP.NET Core project http://www.html.am/html-codes/marquees/css-scrolling-text.cfm How do I execute js sctipt after animation is finished? Something like that, I want to refresh page after animation is finished

    <script>
       function myFunction() {
           location.reload();
       }
    </script>
Share Improve this question asked Jun 7, 2018 at 13:11 IntegerOverlordIntegerOverlord 1,6373 gold badges18 silver badges38 bronze badges 2
  • try using js animation. – Ullas Hunka Commented Jun 7, 2018 at 13:18
  • this may help davidwalsh.name/css-animation-callback – Alex Terry Commented Jun 7, 2018 at 13:36
Add a ment  | 

1 Answer 1

Reset to default 17

All you really need to do is create a Javascript event listener:

The example below creates an event listener for the circle object. You can run the example to see it live.

Also, all of the CSS / circle stuff is just for the animation, all you really need to look at is the javascript portion.

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>

发布评论

评论列表(0)

  1. 暂无评论