js to achieve the pop-up effect

js to achieve the pop-up effect

This article example shares the specific code of js to achieve the pop-up effect for your reference. The specific content is as follows

Use display to control the display and hiding of pop-up windows

<!-- Popup layer -->
<div id="popLayer"></div> <!--Black mask-->
<div id="popBox">
  <div class="close">
   X
  </div>
  <div>
   <!-- Contents -->
 </div>
</div>

js:

//Click the close button var close = document.querySelector(".close")
close.onclick = function () {
 console.log("click")
 var popBox = document.getElementById("popBox");
 var popLayer = document.getElementById("popLayer");
 popBox.style.display = "none";
 popLayer.style.display = "none";
}


//Call when display is neededvar popLayer = document.getElementById("popLayer");
popBox.style.display = "block";
popLayer.style.display = "block";

CSS:

/* Popup layer*/
#popLayer {
 display: none;
 background-color: #000;
 position: absolute;
 top: 0;
 right: 0;
 bottom: 0;
 left: 0;
 z-index: 10;
 opacity: 0.6;
}

/*Popup layer*/
#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;
}

/*Close button*/
#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;
}

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • Toast usage in vue.js and example code using toast pop-up box
  • Vue.js implements pop-up window only once
  • js+html5 realizes the effect of semi-transparent mask layer pop-up box
  • Encapsulation of js custom pop-up box plug-in
  • Implement the delivery address pop-up box selection based on layer.js and return the corresponding address information
  • js to achieve the effect of up, down, left, and right pop-up boxes
  • Solution to the problem of struts json type exception returning to js pop-up box
  • JavaScript to achieve a pop-up box that cannot be closed
  • Easily implement js pop-up box display options
  • Example code of Bootstrap and Angularjs with homemade pop-up box

<<:  Detailed example of mysql trigger usage

>>:  How to modify the time in centos virtual machine

Recommend

A brief discussion on how to customize the host file in Docker

Table of contents 1. Command 2. docker-compose.ym...

How to use union all in MySQL to get the union sort

Sometimes in a project, due to some irreversible ...

Implementation of vue3.0+vant3.0 rapid project construction

Table of contents 1. Project Construction 2. Vue3...

Let’s talk in detail about how browsers view closures

Table of contents Preface Introduction to Closure...

vue uses Ele.me UI to imitate the filtering function of teambition

Table of contents Problem Description The general...

SVN installation and basic operation (graphic tutorial)

Table of contents 1. What is SVN 2. Svn server an...

JS implements a simple todoList (notepad) effect

The notepad program is implemented using the thre...

MySQL 8.0.25 installation and configuration method graphic tutorial

The latest download and installation tutorial of ...

How to optimize MySQL query speed

In the previous chapters, we introduced how to ch...

Summary of mysqladmin daily management commands under MySQL (must read)

The usage format of the mysqladmin tool is: mysql...

JavaScript to achieve a simple carousel effect

What is a carousel? Carousel: In a module or wind...

Detailed explanation of HTML form elements (Part 1)

HTML forms are used to collect different types of...

Summary of several implementations of returning to the top in HTML pages

Recently, I need to make a back-to-top button whe...

WeChat applet implements the snake game

This article shares the specific code of the WeCh...