jQuery Click Popup Layer Popup Modal Box Click Modal Box Disappear Code Sharing

  • 2021-07-13 04:00:41
  • OfStack

No more nonsense, just post the code for everyone. The specific code is as follows:

<!DOCTYPE html>
 <title>jQuery Ejection layer   Modal frame </title>
 <script src="./jquery.min.js" type="text/javascript"></script>
   display: none;
   position: fixed;
   width: 100%;
   height: 100%;
   background-color: black;
   top: 0;
   left: 0;
   right: 0;
   left: 0;
   margin: auto;
   background-color: rgba(0,0,0,0.8);
  .white_content {
   display: none;
   position: fixed;
   overflow: auto;
 <script type="text/javascript">
  $(function () {
   // Eject hidden layer 
   function ShowDiv(show_div,bg_div){
    document.getElementById(bg_div).style.display='block' ;
    var _windowHeight = $(window).height(),// Get the current window height 
      _windowWidth = $(window).width(),// Gets the current window width 
      _popupHeight = $("#"+show_div).height(),// Get the pop-up layer height 
      _popupWeight = $("#"+show_div).width();// Get the pop-up layer width 
    _posiTop = (_windowHeight - _popupHeight)/2;
    _posiLeft = (_windowWidth - _popupWeight)/2;
    $("#"+show_div).css({"left": _posiLeft + "px","top":_posiTop + "px","display":"block"});// Settings position
   // Close the pop-up layer 
   function CloseDiv(show_div,bg_div)
   $(".btn").click(function () {
    var src = $(this).attr("src");
   $("#fade").click(function () {
<!--<input id="Button1" type="button" value=" Click the pop-up layer " onclick="ShowDiv('MyDiv','fade')" />-->
<!-- Please change the picture to your own, and click the picture to pop up -->
<img src="tu.png" alt="sd" class="btn" >
<img src="pic.jpg" alt="sd" class="btn" >
<!-- Background layer when ejecting layer DIV-->
<div id="fade" class="black_over">
<!-- Contents of the pop-up layer -->
<div id="MyDiv" class="white_content">
<img src="tu.png" alt="" id="showcont">

Related articles: