css兼容各游览器悬浮代码

position:fixed兼容性

IE6不支持position:fixed,解决方法是ie6 css hack,设置_position: absolute; _marin _top _bottom _left ...

position:fixed在IE6中使用
本文所使用的技巧是用了一条Internet Explorer的CSS表达式(expression)。你不可以直接使用该表达式,因为它可能会因为缓存而不更新。解决这一点的最简单的方式是使用eval包裹你的语句。

如何解决“振动”的问题?
显然IE有一个多步的渲染进程。当你滚动或调整你的浏览器大小的时候,它将重置所有内容并重画页面,这个时候它就会重新处理css表达式。这会引起一个丑陋的“振动”bug,在此处固定位置的元素需要调整以跟上你的(页面的)滚动,于是就会“跳动”。

解决此问题的技巧就是使用background-attachment:fixed;为body或html元素添加一个background-image。这就会强制页面在重画之前先处理CSS。因为是在重画之前处理CSS,它也就会同样在重画之前首先处理你的CSS表达式。这将让你实现完美的平滑的固定位置元素!

你可以使用一个about:blank替代一个spacer.gif图片

<!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 http-equiv="X-UA-Compatible" content="IE=7" />
<title>chmod755 - 演示站</title>
<style type="text/css">
html,body{margin:0; padding:0;background-image:url(about:blank);background-attachment:fixed;}

.wrap{height:2000px; background:blue}
.float
{
     background-color: red;
    text-align: center;
    font-size: 12px;
    z-index: 9999;
    position: fixed;
    _position: absolute;
}

#top{
    width:100%;
    height:50px;
    line-height: 50px;
    top: 0;
    _top: expression(eval(documentElement.scrollTop));
    _bottom:auto;
}

#center{
    width:200px;
    height:100px;
    line-height:100px;
    margin:-50px 0 0 -100px;
    top: 50%;
    left: 50%;
    _top: expression(eval(documentElement.scrollTop + (document.documentElement.clientHeight-this.offsetHeight)/2));
    _left: expression(eval(documentElement.scrollLeft + (document.documentElement.clientWidth-this.offsetWidth)/2));
    _margin:0;
}

#fotter{
    width:100%;
    height:50px;
    line-height: 50px;
    bottom:0;
    margin:-50px 0 0 0;
    _top:expression(eval(document.documentElement.scrollTop+document.documentElement.clientHeight-this.offsetHeight-(parseInt(this.currentStyle.marginTop,10)||0)-(parseInt(this.currentStyle.marginBottom,10)||0)));
    _margin:0;
}

#right_center{
    width:100px;
    height:200px;
    line-height: 200px;
    right: 0;
    top: 50%;
    margin:-100px 0 0 0;
    _top: expression(eval(documentElement.scrollTop + (document.documentElement.clientHeight-this.offsetHeight)/2));
    _margin:0;
    _right:-1px;
}

#right_fotter{
    background:green;
    width:100px;
    height:200px;
    line-height: 200px;
    right: 0;
    bottom:0;
    _top:expression(eval(document.documentElement.scrollTop+document.documentElement.clientHeight-this.offsetHeight-(parseInt(this.currentStyle.marginTop,10)||0)-(parseInt(this.currentStyle.marginBottom,10)||0)));
    _right:-1px;


}

</style>
</head>
<body>
    <div class="float" id="top">顶部</div>
    <div class="float" id="center">垂直居中</div>
    <div class="float" id="fotter">底部</div>
    <div class="float" id="right_center">右中</div>
    <div class="float" id="right_fotter">右下</div>
    <div class="wrap"></div>
</body>
</html>

 

转载于:https://www.cnblogs.com/chmod755/p/3303184.html

1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 、4下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合;、下载 4使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合;、 4下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值