JS \ CSS align the image vertically

Source: Internet
Author: User

Document: use JavaScript to obtain the height and width of the current window

< Script Language = "JavaScript" >
VaR S =   "" ;
S + =   " Visible area width: "   + Document. Body. clientwidth;
S + =   " <Br> the visible area of the webpage is high: " + Document. Body. clientheight;
S + =   " <Br> webpage visible area width: " + Document. Body. offsetwidth + " (Including edges and scroll bars) " ;
S + =   " <Br> the visible area of the webpage is high: " + Document. Body. offsetheight + " (Including edges) " ;
S + =   " <Br> webpage text width: " + Document. Body. scrollwidth;
S + =   " <Br> webpage body: " + Window. screentop;
S + =   " <Br> left part of the webpage body: " + Window. screenleft;
S + =   " <Br> high screen resolution: " + Window. Screen. height;
S + =   " <Br> screen resolution width: " + Window. Screen. width;
S + =   " <Br> available workspace height: " + Window. Screen. availheight;
S + =   " <Br> available workspace width: " + Window. Screen. availwidth;
S + =   " <Br> your screen settings are " + Window. Screen. colordepth + " Bit color " ;
S + =   " <Br> set your screen " + Window. Screen. devicexdpi + " Pixel/inch " ;
Document. Write (s );
</ Script >

Code:

< Html >

< Body Onresize = "Myload ()" Onload = "Myload ()" >

< Div ID = "Xuanma" Style = "Z-INDEX: 1; left: 0px; position: absolute; top: 0px" >
< IMG ID = "Ximage" SRC = "Yah/groupimages/060823nhp1.jpg" />
</ Div >

< Script Language = "JavaScript" Type = Text/JavaScript >
Function Myload ()
{
Document. getelementbyid ('x'). style. Top = Document. Body. clientheight / 2 - Document. getelementbyid ('ximage'). Height / 2 ;
Document. getelementbyid ('x'). style. Left = Document. Body. clientwidth / 2 - Document. getelementbyid ('ximage'). Width / 2 ;
}

</ Script >

</ Body >
</ Html >
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.