码迷,mamicode.com
首页 > Web开发 > 详细

js实现div居中

时间:2014-12-05 22:35:59      阅读:279      评论:0      收藏:0      [点我收藏+]

标签:des   style   blog   http   io   ar   os   sp   java   

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
<title>test</title>
<meta name="keywords" content=""/>
<meta name="description" content=""/>
<link type="text/css" rel="stylesheet" href="http://j.laohe360.net/css/pub.css"/>
<script charset="utf-8" type="text/javascript" src="http://www.php100.com/statics/js//php100/js/jquery.js"></script>
<script>
$(document).ready(function () {
	//alert(document.documentElement.clientHeight);
	//alert(document.documentElement.clientWidth);
	var iWidth=500; //弹出窗口的宽度;
	var iHeight=400; //弹出窗口的高度;
	var iTop = (document.documentElement.clientHeight-iHeight)/2; //获得窗口的垂直位置;
	var iLeft = (document.documentElement.clientWidth-iWidth)/2; //获得窗口的水平位置;
	$("#tpsp").height(iHeight)
		.width(iWidth)
		.css(‘position‘,‘absolute‘)
		.css("top",iTop)
		.css("left",iLeft)
		.css("background",‘red‘);
});

</script>
</head>
<body>


<div id="tpsp">
	
</div>


</body>
</html>

 

js实现div居中

标签:des   style   blog   http   io   ar   os   sp   java   

原文地址:http://www.cnblogs.com/yuwensong/p/4147558.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!