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

首頁 > 開發 > CSS > 正文

ie6下實現position:fixed效果實例介紹

2024-07-11 08:36:42
字體:
來源:轉載
供稿:網友

建議:盡可能的手寫代碼,可以有效的提高學習效率和深度。
由于IE6并不支持position:fixed,所以導致很多好的效果都無法實現,但是在IE6下并不是不能夠實現,下面就通過一段實例介紹一下如何實現此種效果。代碼實例如下:


<!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″ />
<meta name=”author” content=”http://www.softwhy.com/” />
<title>螞蟻部落</title>
<style type=”text/css”>
body
{
margin:40px;
padding:0px;
border:1px solid blue;
}
.first
{
width:300px;
height:600px;
border:1px solid red;
margin:20px;
}
.first .fixed
{
width:100px;
height:100px;
background-color:black;
position:fixed;
_margin-top:20px;
_position:absolute;
_top:expression(eval(document.documentElement.scrollTop));
left:20px;
top:20px;
}
</style>
</head>
<body>
<div class=”first”>
<div class=”fixed”></div>
</div>
</body>
</html>

以上代碼可以兼容IE6和其他主流瀏覽器,實現此效果的核心代碼是:

復制代碼代碼如下:
_top:expression(eval(document.documentElement.scrollTop));

注意:加上了上面這一行代碼之后,IE6下top功能失效了,所以要加一個_margin-top。
雖然上面的代碼實現了想要的功能,但是還是有點問題,那就是當拖動滾動條的時候會出現顫抖現象。代碼修改如下:


<!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″ />
<meta name=”author” content=”http://www.softwhy.com/” />
<title>螞蟻部落</title>
<style type=”text/css”>
*html
{
background-image:url(about:blank);
background-attachment:fixed;
}
body
{
margin:40px;
padding:0px;
border:1px solid blue;
}
.first
{
width:300px;
height:600px;
border:1px solid red;
margin:20px;
}
.first .fixed
{
width:100px;
height:100px;
background-color:black;
position:fixed;
_margin-top:20px;
_position:absolute;
_top:expression(eval(document.documentElement.scrollTop));

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 乌审旗| 西贡区| 宁德市| 昌吉市| 青岛市| 金川县| 吉隆县| 龙口市| 云浮市| 孝昌县| 丰顺县| 灵川县| 卢氏县| 平泉县| 长顺县| 寻乌县| 本溪| 济源市| 汽车| 全南县| 成都市| 柳林县| 寿光市| 兴义市| 乃东县| 错那县| 昆明市| 平昌县| 阳朔县| 炉霍县| 兖州市| 昭觉县| 商水县| 营口市| 黄大仙区| 汉源县| 柳州市| 浮山县| 大渡口区| 甘南县| 谷城县|