国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發(fā) > CSS > 正文

ie6 fixed bug的解決方法 (css+js)

2024-07-11 08:26:51
字體:
供稿:網(wǎng)友

復(fù)制代碼
代碼如下:
#fixed {
position: absolute;
top: 0;
left: 0;
width: 10em;
height: 100%;
}
body > #fixed {
position: fixed;
}
#content {
margin-left: 10em;
background:red;
height:800px;
}

利用css選擇器覆蓋原position的屬性值;
fixed層的父層需是body才能這樣實(shí)現(xiàn);
但是這樣還不完美 并不能完全實(shí)現(xiàn)效果,因?yàn)椴粫?huì)隨body頁面拉動(dòng)而滾動(dòng)
要實(shí)現(xiàn)隨body頁面滾動(dòng)而滾動(dòng) 需添加以下js代碼

復(fù)制代碼
代碼如下:
<script language="javascript" type="text/javascript">
function fixedPop1(){
var m=60; //top值
var obj=document.getElementById("TopDivInner"); //position:fixed對(duì)象
var n=50; //top值
var obj2=document.getElementById("TopDiv"); //position:fixed對(duì)象
window.onscroll=function(){obj2.style.top=(document.body.scrollTop||document.documentElement.scrollTop)+n+'px';
obj.style.top=(document.body.scrollTop||document.documentElement.scrollTop)+m+'px';
}
window.onresize=function(){obj2.style.top=(document.body.scrollTop||document.documentElement.scrollTop)+n+'px';
obj.style.top=(document.body.scrollTop||document.documentElement.scrollTop)+m+'px';
}
};
$(function(){
fixedPop1();
});
</script>

豆瓣的彈出登陸框就是利用這樣的方式實(shí)現(xiàn)的,當(dāng)然要在js代碼上加 if IE6的
到此,加上通過js判斷屏幕分辨率進(jìn)而改變彈出框的位置,使其更加合理化,就基本完成了豆瓣彈出登陸款的實(shí)現(xiàn)
 
然而這個(gè)在ie6下存在拖動(dòng)滾動(dòng)條引起登陸框閃動(dòng)的問題,為解決這個(gè)問題可以利用css e xpression 代價(jià)是更高的內(nèi)存占用

復(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>無標(biāo)題文檔</title>
<style type="text/css">
*
{
margin: 0px;
padding: 0px;
}
body {
background-image: url(http://global.tianya.cn/global/gnav/css/nothing.txt);
background-attachment: fixed; /* prevent screen flash in IE6 */
}
#topNavWrapper {
width: 980px;
text-align: left;
height: 31px;
margin: 0px auto;
z-index:100;
_position: relative ;
_top:0px;
}
#topNav {
width: 980px;
float: left;
display: block;
z-index: 100;
overflow: visible;
position: fixed;
top: 0px; /* position fixed for IE6 */
_position: absolute;
_top: e­xpression(documentElement.scrollTop + "px");
background-image: url(http://global.tianya.cn/global/gnav/images/top_r.gif);
background-repeat: no-repeat;
background-position: right;
height: 31px;
}
.show{
position:absolute;
top:500px;
left:400px;
border:#ff0000 1px solid;
}
</style>
</head>
<body>
<div id="topNavWrapper">
<ul class="jd_menu" id="topNav">
</ul>
</div>
這里是大量的br換行標(biāo)簽。
<div class="show">show</div>
</body>
</html>
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 太保市| 临西县| 奉节县| 安顺市| 驻马店市| 乌兰浩特市| 广州市| 宿州市| 襄樊市| 隆回县| 榆林市| 九龙坡区| 东源县| 沅陵县| 宁城县| 台南县| 民县| 金门县| 北辰区| 富蕴县| 海阳市| 高清| 张家港市| 平塘县| 柳河县| 中牟县| 宁德市| 泰安市| 尤溪县| 漳平市| 台东县| 中方县| 南和县| 屏山县| 佛冈县| 青神县| 嵊州市| 新宁县| 资阳市| 建湖县| 安达市|