js实现弹框效果

发布时间:2022-04-16 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了js实现弹框效果脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。

本文实例为大家分享了js实现弹框效果的具体代码,供大家参考,具体内容如下

利用display来控制弹窗的现实和隐藏

<!-- 弹出层 -->
<div id="poplayer"></div> <!--黑色蒙版 -->
<div id="popBox">
  <div class="close">
   X
  </div>
  <div>
   <!-- 内容 -->
 </div>
</div>

js:

//点击关闭按钮
VAR close = document.querySelector(".close")
close.onclick = function () {
 console.LOG("点击")
 var popBox = document.getElementById("popBox");
 var popLayer = document.getElementById("popLayer");
 popBox.style.display = "none";
 popLayer.style.display = "none";
}


//需要显示时调用
var popLayer = document.getElementById("popLayer");
popBox.style.display = "block";
popLayer.style.display = "block";

CSS:

/* 弹出层 */
#popLayer {
 display: none;
 background-color: #000;
 posITion: absolute;
 top: 0;
 right: 0;
 bottom: 0;
 left: 0;
 z-index: 10;
 opacity: 0.6;
}

/*弹出层*/
#popBox {
 display: none;
 background-color: #FFFFFF;
 z-index: 11;
 width: 220px;
 height: 300px;
 position: fixed;
 top: 0;
 right: 0;
 left: 0;
 bottom: 0;
 margin: auto;
}

/*关闭按钮*/
#popBox .close {
 width: 20px;
 height: 20px;
 border-radius: 50%;
 position: absolute;
 border: 1px solid #fff;
 color: #fff;
 text-align: center;
 line-height: 20px;
 right: 8px;
 top: 8px;
 z-index: 50;
}

#popBox .close a {
 text-decoration: none;
 color: #2D2C3B;
}

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本宝典。

脚本宝典总结

以上是脚本宝典为你收集整理的js实现弹框效果全部内容,希望文章能够帮你解决js实现弹框效果所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签:jsjs弹框"