html点击空白处关闭,写一个点击空白区域关闭遮罩的效果

Document

function hh() {

console.log(111111111)

}

.f {

left: 0;

right: 0;

top: 0;

bottom: 0;

z-index: 200;

overflow: hidden;

display: flex;

/* align-items: center;

justify-content: center; */

position: absolute;

background: rgba(0, 0, 0, 0.5);

}

.s {

width: 100%;

height: 300px;

z-index: 300;

background: #fff;

}

#a {

left: 0;

right: 0;

top: 0;

bottom: 0;

z-index: 200;

overflow: hidden;

display: flex;

align-items: center;

justify-content: center;

position: absolute;

background: rgba(0, 0, 0, 0.5);

}

let a = document.getElementById('a')

a.addEventListener(

'click',

function () {

console.log(1)

},

true

)

f7b52dd39ac48ca6ba4434be97de6d64.pngX

原理:写一个父弹窗弹窗,之后两个子弹窗

上面是内容,下面是空白区域(点击关闭),上边的z-index高过下面的弹窗

.window {

left: 0;

right: 0;

top: 0;

bottom: 0;

z-index: 200;

overflow: hidden;

display: flex;

align-items: center;

justify-content: center;

}

.counter-window {

width: 100%;

left: 0;

bottom: 0;

z-index: 200;

background: #fff;

}

.win-shadow {

left: 0;

top: 0;

z-index: 100;

width: 100%;

height: 100%;

background: rgba(0, 0, 0, 0.50);

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值