How do I set a timer for a image to appear in javascript or html?

99封情书 提交于 2019-12-02 16:48:34

问题


Currently I have the following piece of code but it isn't working on my facebook iframe application.

function Timer(){
    document.getElementById('buybtn').style.visibility = "visible"; 
    setTimeout(Timer,1080000);
}

and the following html:

<p style="text-align: center;">'</p>
<div id="buybtn">
   <p style="text-align:center">
      <a href="http://www.google.com" target="_blank">
         <img src="http://www.adspecialist.be/wp-content/themes/adspecialist/img/visit-my-website-en.png" border="0" />
       </a>
   </p>
</div>

Could you please let me know how to fix this problem


回答1:


Your code is not supposed to work, because Timer() will never be called since you have your timeout inside the function. Move it outside and it will work.

function Timer(){
    document.getElementById('buybtn').style.visibility = "visible"; 
}

setTimeout(Timer,3000);

demo jsfiddle



来源:https://stackoverflow.com/questions/20476440/how-do-i-set-a-timer-for-a-image-to-appear-in-javascript-or-html

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