Home>Article>Web Front-end> How to implement pop-up layer in javascript

How to implement pop-up layer in javascript

藏色散人
藏色散人 Original
2023-02-10 10:21:44 1712browse

Javascript method to implement a pop-up layer: 1. Create an HTML sample file; 2. Hide the content to be displayed first, and after the click condition is triggered, display the originally hidden content, with code such as "document. getElementById("open").onclick = function(e){...}"; 3. Provide a mask layer to cover all the original page content.

How to implement pop-up layer in javascript

The operating environment of this tutorial: Windows 10 system, javascript version 1.8.5, Dell G3 computer.

How to implement pop-up layer in javascript?

Use JAVASCRIPT to achieve the pop-up layer effect

Statement

Reading this article requires a certain amount of HTML, CSS and JavaScript Basics

Design

The idea of implementing the pop-up layer effect is very simple: hide the content to be displayed first, and after triggering a certain condition (such as clicking a button), Reveal previously hidden content.

Implementation

   Window对象  
百度一下

The display effect is as follows:

How to implement pop-up layer in javascript

But we can notice that after popping up the hidden content, we can still enter the Baidu page through the link. In order to prevent this from happening, we can provide a mask layer to cover all the original page content. The code is as follows:

   Window对象  
百度一下

This is to test the effect again, as shown below:

How to implement pop-up layer in javascript

Summary

The above content The pop-up layer effect is simply implemented, but more complex functions can be implemented on this basis by adding more code.

Recommended learning: "JavaScript Video Tutorial"

The above is the detailed content of How to implement pop-up layer in javascript. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn