This article mainly introduces jQuery mask layer examples in detail, which has certain reference value. Interested friends can refer to it. I hope it can help everyone.
1.1 Background translucency The mask layer style
requires a black (or other) background and must be set to absolute positioning. The following is the css style used in the project:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | #overlay {
background: #000;
filter: alpha(opacity=50);
opacity: 0.5;
display: none;
position: absolute;
top: 0px;
left: 0px;
width: 100%;
height: 100%;
z-index: 100;
display:none;
}
|
Copy after login
1.2 jQuery to implement mask
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | function showOverlay() {
$( "#overlay" ).height(pageHeight());
$( "#overlay" ).width(pageWidth());
$( "#overlay" ).fadeTo(200, 0.5);
}
function hideOverlay() {
$( "#overlay" ).fadeOut(200);
}
function pageHeight() {
return document.body.scrollHeight;
}
function pageWidth() {
return document.body.scrollWidth;
}
|
Copy after login
1.3 Prompt box
Mask The purpose of the mask is just to make it impossible to operate the content and highlight the prompt box. The prompt box can be made by referring to the above. The z-index can be higher than the mask layer. The main question is how to control the prompt box to be centered in the browser.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | function adjust(id) {
var w = $(id).width();
var h = $(id).height();
var t = scrollY() + (windowHeight()/2) - (h/2);
if (t < 0) t = 0;
var l = scrollX() + (windowWidth()/2) - (w/2);
if (l < 0) l = 0;
$(id).css({left: l+'px', top: t+'px'});
}
function windowHeight() {
var de = document.documentElement;
return self.innerHeight || (de && de.clientHeight) || document.body.clientHeight;
}
function windowWidth() {
var de = document.documentElement;
return self.innerWidth || (de && de.clientWidth) || document.body.clientWidth
}
function scrollY() {
var de = document.documentElement;
return self.pageYOffset || (de && de.scrollTop) || document.body.scrollTop;
}
function scrollX() {
var de = document.documentElement;
return self.pageXOffset || (de && de.scrollLeft) || document.body.scrollLeft;
}
|
Copy after login
Related recommendations:
jQuery implements the function of automatically popping up the mask layer when opening a web page or clicking to pop up the mask layer
How to prevent the page from scrolling after the mask layer
What is the js special effects mask layer
The above is the detailed content of jQuery mask layer implementation method. For more information, please follow other related articles on the PHP Chinese website!