1. 程式人生 > >原生js簡單實現廣告圖片彈出消失

原生js簡單實現廣告圖片彈出消失

<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>首頁</title>
		<style>
			.father{
				border: 1px solid #FF0000;
				margin: auto;
			}
		</style>
		<script>
			var time;
			function init(){
				//定時器
				time = setInterval("showImg()", 3000);  //引數 1,呼叫的方法 2.時間
			}
			
			function showImg(){
				document.getElementById("img2").style.display = "block";
				clearInterval(time);
				time = setInterval("noShowImg()", 3000);
			}
			function noShowImg(){
				document.getElementById("img2").style.display = "none";
				clearInterval(time);
			}
		</script>
	</head>
	<body onload="init()">	
		<div class = "father">
			<img src="../img/f001a62f-a49d-4a4d-b56f-2b6908a0002c_g.jpg" style="display: none" width="100%"  id="img2"/>
		</div>
	</body>
</html>