ie6支持position:fixed之js方法:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>ie6支持position:fixed之js方法</title>
</head>
<style>
* { padding:0; margin:0;}
body{font-size:14px;line-height:30px;}
* html{background-image:url(about:blank)}/*防止在ie6下閃動*/
.fixed {position:fixed;top:20px;left:20px;width:200px;height:300px;background:#09C;border:1px solid #f60;}
.wrapper { height:100%; overflow:auto;margin-left:300px;}
</style>
<!--[if lt IE 7]>
<style>
#fixed{position:absolute;}
</style>
<script type="text/javascript">
window.οnlοad=function(){
var n=20; //top值
var obj=document.getElementById("fixed"); //position:fixed對象
window.οnscrοll=function(){obj.style.top=(document.body.scrollTop||document.documentElement.scrollTop)+n+'px';}
window.οnresize=function(){obj.style.top=(document.body.scrollTop||document.documentElement.scrollTop)+n+'px';}
}
</script>
<![endif]-->
<body>
<div class="fixed" id="fixed">
	 這裏是固定的模擬fixed的元素
</div>
<div class="wrapper">
	
</div>
</body>
</html>


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章