HTML DOM setTimeout() method

The setTimeout() method is used to call a function or calculation expression after the specified number of milliseconds.

grammar

setTimeout(code,millisec)
parameter description
code Required. The JavaScript code string to be executed after the function to be called.
millisec Required. The number of milliseconds to wait before executing the code.

Tip: setTimeout() executes code only once. If you want to call it multiple times, use setInterval() or let the code itself call setTimeout() again.

<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		
		<script src="../js/jquery-1.11.0.min.js"></script>
		<script>
			//页面加载事件
			$(function(){
    
    
				setTimeout(show,2000)
			})
			function show() {
    
    
				$("#ad").fadeIn(10000);
				setTimeout(hide,2000)
			}
			function hide() {
    
    
				$("#ad").fadeOut(10000);
			}
		</script>
	</head>
	<body>
		<div id="ad" style="width:100%;display: none;">
			<img src="../img/ad_.jpg" width="100%" />
		</div>
		
	</body>
</html>

Guess you like

Origin blog.csdn.net/weixin_45627031/article/details/112200097