js\css 讓圖片垂直置中

來源:互聯網
上載者:User

資料:用JAVASCRIPT擷取當前視窗的高度和寬度

<SCRIPT   LANGUAGE="JavaScript">
var s = "";
s += "網頁可見地區寬:" + document.body.clientWidth;
s += "<br>網頁可見地區高:"+ document.body.clientHeight;
s += "<br>網頁可見地區寬:"+ document.body.offsetWidth +" (包括邊線和捲軸)";
s += "<br>網頁可見地區高:"+ document.body.offsetHeight +" (包括邊線)";
s += "<br>網頁本文全文寬:"+ document.body.scrollWidth;
s += "<br>網頁本文部分上:"+ window.screenTop;
s += "<br>網頁本文部分左:"+ window.screenLeft;
s += "<br>螢幕解析度的高:"+ window.screen.height;
s += "<br>螢幕解析度的寬:"+ window.screen.width;
s += "<br>螢幕可用工作區高度:"+ window.screen.availHeight;
s += "<br>螢幕可用工作區寬度:"+ window.screen.availWidth;
s += "<br>你的螢幕設定是   "+ window.screen.colorDepth   +"   位彩色";
s += "<br>你的螢幕設定   "+ window.screen.deviceXDPI   +"   像素/英寸";
document.write(s);
</script>

代碼:

<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('xuanma').style.top= document.body.clientHeight/2-document.getElementById('ximage').height/2;
document.getElementById('xuanma').style.left= document.body.clientWidth/2-document.getElementById('ximage').width/2;
}

</SCRIPT>

</body>
</html>
相關文章

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.