你要的是固定定位效果吧,不用javascript就可以做到;下面这个例子效果是水平垂直居中页面,并且不随着滚动条变化而改变位置; position:fixed固定定位但IE6不兼容所以用了个hack;你看看下面的例子就明白了;
<html>
<head>
<title>title>
<style type="text/css">
html,body {
overflow:hidden;
margin:0px;
width:100%;
height:100%;
}
.virtual_body {
width:100%;
height:100%;
overflow-y:scroll;
overflow-x:auto;
}
.fixed_div {
position:absolute;
z-index:2008;
bottom:20px;
left:40px;
width:800px;
height:40px;
border:1px solid red;
background:#e5e5e5;
}
style>
head>
<body>
<div class="fixed_div">I am still here!div>
<div class="virtual_body">
<div style="height:888px;">
I am content !
div>
div>
body>
html>