javascript trigger when gif animation is done

二次信任 提交于 2019-12-10 11:23:44

问题


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.


回答1:


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>


来源:https://stackoverflow.com/questions/24385829/javascript-trigger-when-gif-animation-is-done

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!