Js相关技术

定时器:
​ setInterval & clearInterval
​ setTimeout & clearTimeout

显示: img.style.display = "block"
隐藏: img.style.display = "none"

img 对象
​ style属性: style对象

需求分析

当用户打开界面,3秒钟之后弹出广告,这个广告显示5秒钟,隐藏广告

技术分析

定时器: setTimeout
显示和隐藏: style.display = "block/none"

步骤分析:

  1. 导入JQ的文件
  2. 编写JQ的文档加载事件
  3. 启动定时器 setTimeout("",3000);
  4. 编写显示广告的函数
  5. 在显示广告里面再启动一个定时器
  6. 编写隐藏广告的函数

代码实现

<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<script type="text/javascript" src="../js/jquery-1.11.0.js" ></script>
		<!--
			1. 导入JQ的文件
			2. 编写JQ的文档加载事件
			3.  启动定时器 setTimeout("",3000);
			4. 编写显示广告的函数
			5. 在显示广告里面再启动一个定时器
			6. 编写隐藏广告的函数
		-->
		<script>
			//显示广告
			function showAd(){
				$("#img1").slideDown(2000);
				setTimeout("hideAd()",3000);
			}
			
			//隐藏广告
			function hideAd(){
				$("#img1").slideUp(2000);
			}
			
			
			$(function(){
				setTimeout("showAd()",3000);
				
			});
		</script>
	</head>
	<body>
		<img src="../img/f001a62f-a49d-4a4d-b56f-2b6908a0002c_g.jpg"   />
	</body>
</html>

相关文章:

  • 2022-12-23
  • 2021-11-14
  • 2021-07-08
  • 2021-06-23
  • 2021-11-14
  • 2021-11-14
  • 2021-07-15
猜你喜欢
  • 2021-12-02
  • 2021-05-18
  • 2021-05-23
  • 2021-05-06
  • 2022-12-23
  • 2022-12-23
  • 2021-09-08
相关资源
相似解决方案