Home > Web Front-end > JS Tutorial > jQuery DIV pop-up effect implementation code_jquery

jQuery DIV pop-up effect implementation code_jquery

WBOY
Release: 2016-05-16 18:50:41
Original
1038 people have browsed it

First of all, you can click the Close button or click anywhere on the mask layer to close the pop-up layer.

HTML code

Copy code The code is as follows:


title position




Text content





< ;/div>


The code is very concise. The outermost layer is a large DIV as the container of the pop-up layer, H4 as the title of the pop-up layer, another DIV for displaying the text content of the pop-up layer, and another DIV for placing some buttons.
CSS code
Copy the code The code is as follows:

. pop-box {
z-index: 9999; /*This value must be large enough to be displayed on the top*/
margin-bottom: 3px;
display: none;
position: absolute;
background: #FFF;
border:solid 1px #6e8bde;
}

.pop-box h4 {
color: #FFF;
cursor:default ;
height: 18px;
font-size: 14px;
font-weight:bold;
text-align: left;
padding-left: 8px;
padding-top : 4px;
padding-bottom: 2px;
background: url("../images/header_bg.gif") repeat-x 0 0;
}

.pop-box -body {
clear: both;
margin: 4px;
padding: 2px;
}

JS code
Copy code The code is as follows:

function popupDiv(div_id) {
var div_obj = $("#" div_id);
var windowWidth = document.documentElement.clientWidth;
var windowHeight = document.documentElement.clientHeight;
var popupHeight = div_obj.height();
var popupWidth = div_obj.width() ;
//Add and display the mask layer
$("
").addClass("mask")
.width(windowWidth * 0.99)
.height(windowHeight * 0.99)
.click(function() {hideDiv(div_id); })
.appendTo("body")
.fadeIn(200);
div_obj.css({"position": "absolute"})
.animate({left: windowWidth/2-popupWidth/2,
top: windowHeight/2-popupHeight/2, opacity: "show" }, "slow");
}

function hideDiv(div_id) {
$("#mask").remove();
$("#" div_id).animate ({left: 0, top: 0, opacity: "hide" }, "slow");
}
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template