redirect page javascript after animation

0

Well, I'm making a game in HTML5 + CSS3 + JavaScript and I'm in the part of the initial menu. I wanted the button before redirecting the page to make an animation. The animation part is working fine, but from the moment I enter that part of the code to redirect the page, it stops running the animation. Does anyone know how to help? Below I leave the code part in JavaScript.

function ajuda(){
this.style.backgroundPosition = "right";
var sombotao = document.getElementById("sombotao");
sombotao.play();            
window.location.href="ajuda.html";                
}
    
asked by anonymous 24.03.2016 / 16:31

1 answer

3

You can use the event ended of HTML5 , the description is:

  

The event is triggered when the playback is over.

     

The ended event is fired when playback has stopped because the end of the media was reached.

In this case it might look like this:

function ajuda() {
    this.style.backgroundPosition = "right";
    var sombotao = document.getElementById("sombotao");
    audio.addEventListener('ended', function(){
         window.location.href = "ajuda.html";
    });
    sombotao.play();
}
    
24.03.2016 / 16:34