简体   繁体   English

如何使用JavaScript消失动画gif

[英]how to disappear an animated gif with javascript

i have this code and would like to have an animated gif to disappear after 3 seconds. 我有此代码,并希望动画gif在3秒后消失。 i learned that i need to add window.onload=loadingGif(); 我了解到我需要添加window.onload = loadingGif(); to ensure the 'loadingGif' function is fired when the page loads. 以确保在页面加载时触发“ loadingGif”功能。 i stll have the problem that this code is not working how it should do. 我仍然有一个问题,该代码无法正常工作。 i would like to know what is going wrong with that? 我想知道那是怎么回事? thanks. 谢谢。

i´m sorry i posted the wrong code. 对不起,我发布了错误的代码。 it must be: 一定是:

<body>

<script type="text/javascript">
var counter = 3;                              
function downcount() {
  document.getElementById('digit').firstChild.nodeValue = counter ;
  if (counter == 0 ) {
    document.getElementById('loading').style.display = 'none';
    document.getElementById('msg').style.display = 'block';
  } else {
    counter--;
    window.setTimeout('downcount()', 1000);
  }
}
window.onload=downcount;
</script>

<div id="loading">
  <img src="loading/loading40.gif"/>
</div>

<div id="msg" style="display:none">
   <?PHP echo $_SESSION['msg'];?>
</div>

Close the img tag. 关闭img标签。

Also, where's digit? 另外,数字在哪里? If that doesn't exist then you'll be getting JS errors. 如果不存在,那么您将收到JS错误。

You're doing three 1s setTimeout to wait for 3 seconds? 您正在执行三个1s setTimeout以等待3秒? Here is a simpler solution, right out of my head... 这是一个更简单的解决方案,马上就可以解决...

window.onload = setTimeout(removeImg, 3000)
var removeImg = function() {
    document.getElementById('loading').style.display = 'none'
    document.getElementById('msg').style.display = 'block'
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM