The example in this article describes how to implement timing hiding and display of images using JavaScript. Share it with everyone for your reference. The details are as follows:
JavaScript is used here to hide and display images at regular intervals. The image will be automatically displayed or hidden after a few seconds. You can define the number of seconds yourself in the JavaScript code snippet.
The operation effect is as shown below:
The specific code is as follows:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>定时隐藏图片</title> </head> <SCRIPT LANGUAGE="JavaScript"> var sec=10; var timer; function hidepic() { sec--; if (sec==0){ textfield.value = "图片被隐藏"; soccer.style.visibility =(soccer.style.visibility == "hidden") ? "visible" : "hidden"; } else{ textfield.value = "图片会在 "+sec+" 秒后隐藏"; setTimeout("hidepic()",1000); } } </SCRIPT> <body onLoad = "hidepic();"> <center> <input name="textfield" type="text" size="20"> <br> <DIV ID="soccer" STYLE="position:absolute; left:333px; top:43px"> <img border="0" src="http://www.jb51.net/images/logo.gif" > </DIV> </center> </body> </html>
I hope this article will be helpful to everyone’s JavaScript programming design.