用户登录
用户注册

分享至

使用JQuery完成页面定时弹出广告

  • 作者: 霾69967766
  • 来源: 51数据库
  • 2021-09-05

使用jquery完成页面定时弹出广告

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" id="img1" width="100%" style="display:none"  />
	</body>
</html>

软件
前端设计
程序设计
Java相关