jQuery实现广告弹窗显示和隐藏(show(),hide()),弹窗动画

 

目录

 功能:2s后打开广告弹窗,再过3s后自动关闭弹窗。在弹窗显示期间,也可手动点击关闭按钮关闭弹窗

还可以给弹窗添加动画,比如在show(),hide()方法中设置参数:slow,fast,1000(表示1000ms)

toggle():相当于开关。


 功能:2s后打开广告弹窗,再过3s后自动关闭弹窗。在弹窗显示期间,也可手动点击关闭按钮关闭弹窗

<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>jQuery实现广告弹窗</title>
		<script type="text/javascript" src="js/jquery-3.3.1.js" ></script>
		<style type="text/css">
			#ad{
				width: 300px;
				height: 300px;
				background-color: yellowgreen;
				bottom: 0;
				right: 0;
				position: fixed;
				display: none;
			}
		</style>
		<script type="text/javascript">
			setTimeout(function(){
			   $("#ad").show()
			},2000)
			setTimeout(function(){
				$("#ad").hide()
			},5000)
			$(function(){
				$("#closeBtn").click(function(){
					$("#ad").hide();
				})
			})
		</script>
	</head>
	<body>
		<div id="ad">
			<button id="closeBtn">关闭</button>
		</div>
	</body>
</html>

还可以给弹窗添加动画,比如在show(),hide()方法中设置参数:slow,fast,1000(表示1000ms)

<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>jQuery实现广告弹窗</title>
		<script type="text/javascript" src="js/jquery-3.3.1.js" ></script>
		<style type="text/css">
			#ad{
				width: 300px;
				height: 300px;
				background-color: yellowgreen;
				bottom: 0;
				right: 0;
				position: fixed;
				display: none;
			}
		</style>
		<script type="text/javascript">
			setTimeout(function(){
			   $("#ad").show("fast")
			},2000)
			setTimeout(function(){
				$("#ad").hide("slow",function(){
					alert("广告关闭了")
				})
			},5000)
			$(function(){
				$("#closeBtn").click(function(){
					$("#ad").hide(2000);
				})
			})
		</script>
	</head>
	<body>
		<div id="ad">
			<button id="closeBtn">关闭</button>
		</div>
	</body>
</html>

 

toggle():相当于开关。

可以自动判断弹窗是否显示了。如果弹窗是显示状态,则执行关闭功能,如果弹窗是关闭状态,则执行显示功能

<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>jQuery实现广告弹窗</title>
		<script type="text/javascript" src="js/jquery-3.3.1.js" ></script>
		<style type="text/css">
			#ad{
				width: 300px;
				height: 300px;
				background-color: yellowgreen;
				bottom: 0;
				right: 0;
				position: fixed;
				display: none;
			}
		</style>
		<script type="text/javascript">
			setTimeout(function(){
			   $("#ad").toggle("slow");
			},2000)
			
			$(function(){
				$("#closeBtn").click(function(){
					$("#ad").toggle(function(){
							alert("弹窗关闭了");
					});
				})
			})
		</script>
	</head>
	<body>
		<div id="ad">
			<button id="closeBtn">关闭</button>
		</div>
	</body>
</html>

  • 2
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值