gif动画完成后触发javascript [英] javascript trigger when gif animation is done

查看:111
本文介绍了gif动画完成后触发javascript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个上面没有重复gif的网站,因此看起来好像正在加载.我想要一个JavaScript脚本,该脚本可以检测gif何时完成动画制作,然后重定向到另一个站点.

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.

这可能吗?我不能将其设置为5秒左右,因为不同的计算机/平板电脑会在不同的时间加载它.

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

如果您希望看到它的实际效果,请继续访问 https://www. frossblock.dk/misc/loading -据我所知,它在计算机上运行良好,但在平板电脑/手机上,它没有足够的时间完成完整的动画.

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.

推荐答案

在加载GIF时启动一个等于GIF持续时间的计时器;

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" />

并在<head>元素中:

<script type="text/javascript">   
function redirect() 
{  
  window.setTimeout(function() {
    window.location="../index";
  }, 6700);   
} 
</script>

这篇关于gif动画完成后触发javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆