日期:2014-05-17 浏览次数:20676 次
<!DOCTYPE html>
<html>
<head>
<title>模拟position:fixed</title>
</head>
<style>
* { padding:0; margin:0;}
body { height:100%; overflow:hidden; font-size:14px; line-height:2; position:relative;}
html { height:100%; overflow:hidden;}
.fixed { position:absolute; left:50%; margin-left:-100px; top:50%; margin-top:-100px; width:200px;height:200px; background:#fc0;}
.wrapper { height:100%;overflow:auto; overflow-y:scroll;}
#content { width:90%; margin:0 auto; background:#f2f2f2; padding:20px;}
</style>
<body>
<img class="fixed" src="http://avatar.csdn.net/D/E/E/1_shn11160.jpg" alt="shn11160"/>
<div class="wrapper">
<div id="content"></div>
</div>
<script>
var str='';
for(i=0;i<100;i++){
str+= i + "<br />";
}
document.getElementById('content').innerHTML=str;
</script>
</body>
</html>
<html>
<head>
<style type="text/css">
body{
background-image:url("testImg/3.jpg");
background-repeat: no-repeat;
background-attachment: fixed;
background-size: 200px;
background-position: center;
background-color: #acacac;
}
div{
height: 200%;
}
</style>
</head>
<body>
<div></div>
</body>
</html>