关闭广告的案例

55 篇文章 0 订阅
  1. 5s后关闭广告
<div>这是一则广告<span title="关闭广告">×</span></div>
<script>
//获取相关元素
var div = document.getElementsByTagName("div")[0];
setTimeout(function(){
		div.style.display = "none";},5000);
</script>
  1. 点击关闭按钮时,透明度先逐渐降低,再消失
    关闭广告
    CSS部分
<style>
body {
	margin: 0px;
	padding: 0px;
}
div {
	position: relative;
	height: 50px;
	font: 700 20px/50px "simsun";
	text-align: center;
	background: #f00;
	color: #fff;
}
span {
	position: absolute;
	top: 2px;
	right: 2px;
	display: inline-block;
	height: 35px;
	width: 35px;
	font: 400 12px/35px "simsun";
	text-align: center;
	color: #fff;
	cursor: pointer;
}
.un {
	background-color: #000;
	color: #fff;
}
</style>

body部分

<div style="opacity:1">这是一则广告<span title="关闭广告">×</span></div>
<div class="un">我也不知道为什么在这</div>
<script>
//获取相关元素
var div = document.getElementsByTagName("div")[0];
var span = document.getElementsByTagName("span")[0];
span.onclick = function (){
	var timer = null;
	timer = setInterval(function(){
		div.style.opacity -= 0.1;
		if(div.style.opacity<0){
			clearInterval(timer);
			div.style.display = "none";
		}
	},100);
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值