Js css implements the mask layer to overwrite other page elements with drawings and css masks.

Source: Internet
Author: User

Js css implements the mask layer to overwrite other page elements with drawings and css masks.

<div style=" position: fixed; width: 100%; height: 100%; left: 0px; top: 0px; background-color: Black; z-index: 9999; filter: alpha(opacity=70); Opacity:0.7;"></div>

Z-index must be greater than the mask Element

Demo

<! Doctype html> 


The CSS mask layer cannot completely mask pages.

The height: 100% indicates the height of the browser window, that is, the body you set: 100%. If the content on your page exceeds the display range in the browser window, that is, the scroll bar appears. If you pull the scroll bar, the unmasked content will appear below. You can first determine the height of your page content and the size of the browser window, and assign the maximum value to the height of the mask layer.

How does one implement a translucent mask layer after a div layer is displayed on the webpage?

Var p = document. createElement ("DIV ");
P. id = "MyAlertBoxMasker ";
P. style. position = "absolute ";
P. style. width = document. body. scrollWidth;
P.style.height?document.doc umentElement. offsetHeight;
P. style. zIndex = '20140901 ';
P. style. top = '0 ';
P. style. left = '0 ';
P. style. backgroundColor = "gray ";
P. style. opacity = '0. 5 ';
P. style. filter = "alpha (opacity = 80 )";
// Content Layer
Var p1 = document. createElement ("DIV ");
Var top = parseInt (document. body. scrollHeight) * 0.25) + document. body. scrollTop;
P1.id = "MyAlertBox ";
P1.style. position = "absolute ";
Var left;document.doc umentElement. offsetHeight/2;
Var left = 0;
P1.style. zIndex = '20140901 ';
P1.style. top = top + 'px ';
P1.style. left = left + 'px ';

P1.innerHTML = ""; // The specific HTML content of the floating layer
Document. body. appendChild (p );
Document. body. appendChild (p1 );
// The above code appears. -----------

// The following code is disabled
Document. body. removeChild (document. getElementById ('myatertboxmasker '));
Document. body. removeChild (document. getElementById ('myertbox '));

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.