<html>
<head>
<script type="text/javascript" src="./jquery-1.4.4.js"></script>
<style type="text/css">
.divv
{
position:absolute;
top:30%;
left:30%;
width:80px;
height:60px;
border:1px solid #666;
background-color:#9CF;
text-align:center;
}
</style>
<script type="text/javascript">
$(document).ready(
function(){
//页面初始化
goCenter();
//滚动条滚动
$(window).scroll(
function(){
goCenter();
}
);
//拖动浏览器窗口
$(window).resize(
function(){
goCenter();
}
);
}
);
function goCenter()
{
var h = $(window).height();
var w = $(window).width();
var st = $(window).scrollTop();
var sl = $(window).scrollLeft();
$(".divv").css("top", ((h-60)/2)+st);
$(".divv").css("left", ((w-80)/2)+sl);
}
</script>
</head>
<body>
<div class="divv">中央窗口</div>
</body>
</html>
让DIV块保持在浏览器窗口中央位置
最新推荐文章于 2022-07-17 18:05:48 发布