Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

javascript trigger when gif animation is done

I have a site with a not-repeating gif on it, so it looks like it is loading. I would like a javascript script that detects when the gif is done animating, and then redirects to another site.

Is this possible? I can't just set it to like 5 seconds, because diffrent computers/tablets load it in diffrent times.

If you would like to see it in action, then please go ahead and visit https://www.frossblock.dk/misc/loading - It works fine on computers as far as i know, but on tablets/phones it does nt have time enough to complete the full animation.

like image 423
Sn0wy Avatar asked Dec 02 '25 02:12

Sn0wy


1 Answers

Start a timer equal to the GIF duration when the GIF has loaded;

<img onload="redirect();" style="position:absolute;top:0;bottom:80px;right:0;left:0;margin:auto;" src="../images/loading.gif"" width="150" height="150" />

And in the <head> element:

<script type="text/javascript">   
function redirect() 
{  
  window.setTimeout(function() {
    window.location="../index";
  }, 6700);   
} 
</script>
like image 80
Alex K. Avatar answered Dec 03 '25 19:12

Alex K.