首页 > 其他 > 详细

div在IE6中固定

时间:2014-12-14 22:25:06      阅读:395      评论:0      收藏:0      [点我收藏+]

在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:0; padding:0; }
body { height:1000px; }
div { position:fixed; bottom:0; right:0; 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) != -1)//判断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>

 

div在IE6中固定

原文:http://www.cnblogs.com/heboliufengjie/p/4163059.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!