欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

IE6 fixed的完美解決方案

 更新時(shí)間:2011年03月31日 00:38:02   作者:  
IE7已經(jīng)支持position:fixed了,而我們的IE6呢?還繼續(xù)使用js事件?消耗資源,破壞結(jié)構(gòu),畫面閃耀。
第一種方法:純CSS
目前網(wǎng)上有的比較多的是這種解決方案(純CSS):
復(fù)制代碼 代碼如下:

html{overflow:hidden;}
body{height:100%;overflow:auto;}
#rightform form{position:absolute;right:30px;top50px;}

  這個(gè)方法有一個(gè)bug未解決:在IE6下會(huì)把所有position:absolute都變成“浮動(dòng)”的元素;還有使用js方法滾動(dòng)滾動(dòng)條時(shí)會(huì)出現(xiàn)對(duì)象閃爍,如下方法結(jié)合了CSS和js的辦法,解決了以上的問題。
復(fù)制代碼 代碼如下:

<!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=gb2312" />
<title>IE6 fixed</title>
<style type="text/css">
*
{
margin: 0px;
padding: 0px;
}
body {
_background-image: url(about:blank); /*用瀏覽器空白頁面作為背景*/
_background-attachment: fixed; /* prevent screen flash in IE6 確保滾動(dòng)條滾動(dòng)時(shí),元素不閃動(dòng)*/
}
#topNav {
width: 980px;
z-index: 100; /*設(shè)置浮動(dòng)層次*/
overflow: visible;
position: fixed;
top: 50px; /* 其他瀏覽器下定位,在這里可設(shè)置坐標(biāo)*/
_position: absolute; /*IE6 用absolute模擬fixed*/
_top: expression(documentElement.scrollTop + 50 + "px"); /*IE6 動(dòng)態(tài)設(shè)置top位置*/
/* documentElement.scrollTop 設(shè)置浮動(dòng)元素始終在瀏覽器最頂,可以加一個(gè)數(shù)值達(dá)到排版效果 */
background-color:#0000FF;
height: 31px;
}
.show{
position:absolute;
top:500px;
left:400px;
border:#ff0000 1px solid;
}
</style>
</head>
<body>
<div class="jd_menu" id="topNav">1111</div>
<br /><br /><br /><br /><br /><br /><br /><br /><br />
<br /><br /><br /><br /><br /><br /><br /><br /><br />
<br /><br /><br /><br /><br /><br /><br /><br /><br />
<br /><br /><br /><br /><br /><br /><br /><br /><br />
<br /><br /><br /><br /><br /><br /><br /><br /><br />
<br /><br /><br /><br /><br /><br /><br /><br /><br />
<br /><br /><br /><br /><br /><br /><br /><br /><br />
<br /><br /><br /><br /><br /><br /><br /><br /><br />
<br /><br /><br /><br /><br /><br /><br /><br /><br />
<br /><br /><br /><br /><br /><br /><br /><br /><br />
<br /><br /><br /><br /><br /><br /><br /><br /><br />
<div class="show">show</div>
</body>
</html>

只實(shí)現(xiàn)了垂直方向的fixed。若要實(shí)現(xiàn)水平方向的fixed,設(shè)置_left:expression(documentElement.scrollLeft + "px");
  利用給<body>設(shè)置固定的背景,防止?jié)L動(dòng)條滾動(dòng)時(shí)的閃動(dòng);如果<body>中要設(shè)置滾動(dòng)的背景而產(chǎn)生沖突,可以把代碼寫在html選擇器里面,如:
復(fù)制代碼 代碼如下:

html {
_background-image: url(about:blank);
_background-attachment: fixed; /* prevent screen flash in IE6 */
}
body {
background-image: url(1.jpg);
background-attachment: scroll;
}

第二種方法 JavaScript
復(fù)制代碼 代碼如下:

<!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" />
<style type="text/css">
body{ margin:0px; padding:0px; font-size:12px; line-height:22px;}
p{ margin:0px; padding:36px;}
.float2{ position:absolute; padding:26px; border:#999999 3px solid; background-color:#3399FF; right:200px; top:200px;}
.fixed{ position:absolute; right:60px; top:100px; border:#666666 3px solid; background-color:#CCCCCC; padding:26px;}
</style>
<script language="javascript" type="text/javascript">
window.onload=function(){
var n=100; //top值
var obj=document.getElementById("fixed"); //position:fixed對(duì)象
window.onscroll=function(){obj.style.top=(document.body.scrollTop||document.documentElement.scrollTop)+n+'px';}
window.onresize=function(){obj.style.top=(document.body.scrollTop||document.documentElement.scrollTop)+n+'px';}
}
</script>
<title>position_fixed測(cè)試</title>
</head>
<body>
<p>測(cè)試內(nèi)容.........</p>
<p>測(cè)試內(nèi)容.........</p>
<p>測(cè)試內(nèi)容.........</p>
<p>測(cè)試內(nèi)容.........</p>
<p>測(cè)試內(nèi)容.........</p>
<p>測(cè)試內(nèi)容.........</p>
<p>測(cè)試內(nèi)容.........</p>
<p>測(cè)試內(nèi)容.........</p>
<p>測(cè)試內(nèi)容.........</p>
<p>測(cè)試內(nèi)容.........</p>
<p>測(cè)試內(nèi)容.........</p>
<p>測(cè)試內(nèi)容.........</p>
<p>測(cè)試內(nèi)容.........</p>
<p>測(cè)試內(nèi)容.........</p>
<p>測(cè)試內(nèi)容.........</p>
<div class="float2">浮動(dòng)的內(nèi)容2</div>
<div class="fixed" id="fixed">我的位置是固定的!拉動(dòng)滾動(dòng)條看效果。</div>
</body>
</html>

ie6對(duì)postion:fixed的完美解決方案
今天去一老外站看到了這他站上的十分平滑但卻沒有js,好奇,原來。。巧妙啊,分享下,相對(duì)而言比較節(jié)省資源。但效果好,使用方便,兼顧w3c。哈哈
<!-- compliance patch for microsoft browsers -->
<!--[if lt IE 7]><link rel="stylesheet" href="ie-stuff.css" type="text/css" media="screen"/><![endif]-->
ie-stuff.css
復(fù)制代碼 代碼如下:

#footer {
position: absolute;
bottom: auto;
clear: both;
top:expression(eval(document.compatMode &&
document.compatMode=='CSS1Compat') ?
documentElement.scrollTop
+(documentElement.clientHeight-this.clientHeight) - 1
: document.body.scrollTop
+(document.body.clientHeight-this.clientHeight) - 1);
}

相關(guān)文章

最新評(píng)論