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:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | <!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>
|
Copy after login
I hope this article will be helpful to everyone’s JavaScript programming design.