Javascript Pop-up Layer Center effect

Source: Internet
Author: User
The code is as follows Copy Code
<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" >
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 ">
<title>javascript Pop-up Layer Center </title>

<script type= "Text/javascript" >
Window.onload = Show_center; Page finishes loading trigger event
OnResize = Show_center; Trigger event when browser changes size


function Show_center () {

var body_width = document.body.clientWidth;
var body_height = document.body.clientHeight;
var div_width = document.getElementById ("Show_center"). clientwidth;
var div_height = document.getElementById ("Show_center"). clientwidth;

var div_left = (body_width-div_width)/2;
var div_top = (body_height-div_height)/2;

if (body_height <= div_height) {div_top = 0;}
if (body_width <= div_width) {div_left = 0;}
document.getElementById ("Show_center"). Style.left = div_left + ' px ';
document.getElementById ("Show_center"). Style.top = div_top + ' px ';
}
</script>
<body style= "Background-color: #666" >
<div id= "Show_center" style= "Position:absolute;width:200px;height:100px;background-color: #000; Color: #fff; border:2px solid #fff "> Center display </div
</body>

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.