A simple example _javascript technique for the center of the window with JS

Source: Internet
Author: User

In some pages, we always encounter some of the window is not centered, but also according to the size of the browser to adjust the pop-up window popup position,

I've had this problem before, and now I'm presenting to you what I know.

CSS Styles

. windowbox{

  width:500px;

mid-tanbox{

  position:fixed; top:50%; left:50%;  Margin-left: -250px; Background: #fff; border:1px solid red; Display:none

}

HTML code

<div class= ' Windowbox ' >

 <div class = "Mid-tanbox" ></div>

 <div class= "Jclick" > Pinball window </div>

</div>

jquery Code Automatic:

$ (". Jclick"). Click (function (i) {

 var height = $ (". Mid-tanbox"). Height ();

 var eheight = HEIGHT/2;

 $ (". Mid-tanbox"). EQ (i). CSS ("Margin-top", "-eheight");

The above is small series for everyone to bring the JS to achieve a simple example of the center of the bullet window all the content, I hope that we support cloud Habitat Community ~

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.