gif动画完成时的javascript触发 [英] javascript trigger when gif animation is done
问题描述
我有一个网站,上面有一个不重复的 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" />
并且在 元素中:
<script type="text/javascript">
function redirect()
{
window.setTimeout(function() {
window.location="../index";
}, 6700);
}
</script>
这篇关于gif动画完成时的javascript触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!