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: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.οnlοad=window.οnscrοll=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>

 

转载于:https://www.cnblogs.com/heboliufengjie/p/4163059.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值