点击除了弹层的其它位置,怎么隐藏弹层呢?
示例如下:
js:
$('.com-introduce .share').on('click',function(e){
$('.share-box').removeClass('hide')
e.stopPropagation();
})
$('body').on('click',function(){
if(!$(".share-box").hasClass("hide")){
$(".share-box").addClass("hide")
}
})
html:
<div class="left-part">
<div class="share"><i class="i-share"></i>分享</div>
<div class="share-box hide"> // css文件别漏了hide样式
这是个弹层
</div>
</div>
css:
.com-introduce .con .left-part{position: absolute;left: 0;top:0;}
.com-introduce .con .share{cursor: pointer; width: 63px;height: 24px;margin: 0 auto;line-height: 24px;text-align: center;background: #EBF3FA;border-radius: 12px;font-size: 12px;font-weight: 400;color: #999999;}
.com-introduce .con .i-share{margin-right: 3px; display: inline-block;vertical-align: sub; background: url(i-share@2x.png) no-repeat;background-size: cover; width: 17px;height: 17px;}
.com-introduce .con .share-box{padding: 27px 0 0 25px;position: absolute;bottom: -94px; background: url(share-bg.png) no-repeat;width: 148px;height: 70px;} // 尝试的话可以自行给个背景色来模拟
.hide{display:none;}
|