div在IE6中固定

时间:2023-03-09 19:17:24
div在IE6中固定

在IE6中固定一div在右下角,但是ie6不支持position:fixed属性,那么只能通过js实现,通过js判断浏览器在ie6的情况下,div的position为absoluate;right:0;bottom:0;indexOf() 方法对大小写敏感,如果要检索的字符串值没有出现,则该方法返回 -1。

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="author" content="智能社 - zhinengshe.com">
<meta name="copyright" content="智能社 - zhinengshe.com">
<title>智能社 - www.zhinengshe.com</title>
<style>
* { margin:; padding:; }
body { height:1000px; }
div { position:fixed; bottom:; right:; width:100px; height:100px; background:red;
_position:absolute; _bottom:auto;/*_position仅ie6识别*/
}
</style> <script>
window.onresize=window.onload=window.onscroll=function (){
if(window.navigator.userAgent.indexOf('MSIE 6.0') != -)//判断ie6情况下
{
var oDiv=document.getElementById('div1');
var nHeight=oDiv.offsetHeight;
var scrollTop=document.documentElement.scrollTop || document.body.scrollTop;
var a=document.documentElement.clientHeight-nHeight+scrollTop;//可视区的高度减去div盒子模型的高度加上滚动条的高度
oDiv.style.top=a+'px';
}
};
</script>
</head> <body>
<div id="div1"></div>
</body>
</html>