ie 怪异模式下 position fixed javascript 实现

本文提供了一种在Internet Explorer浏览器中实现position fixed效果的方法。通过检测浏览器类型并使用绝对定位来模拟fixed行为,确保页面元素在滚动时能够固定在视口中的特定位置。
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
修改的页面文档类型竟然定义成这个,我太无语了。
好多属性什么的都不对,我太郁闷了。为了实现 position fixed 效果只能写了下面的代码 - -。

var isIE=!!window.ActiveXObject;
if (isIE) {
document.getElementById('notice').style.position = 'absolute';
tValue = 260;
if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
hWindow = document.documentElement.clientHeight;
}else {
hWindow = document.body.clientHeight;
}
window.onscroll = function(){
var el = document.getElementById('notice');
if (document.body && document.body.scrollTop)
{
//top=document.body.scrollTop;
//left=document.body.scrollleft;
if (!isNaN(document.body.scrollTop)) {
//var h = hWindow + document.body.scrollTop - 210;
el.style.top = (hWindow + document.body.scrollTop - tValue) +"px";
}
//console.log('body: '+ document.body.scrollTop);
//console.log('bottom: '+ el.style.bottom);
}
if (document.documentElement && document.documentElement.scrollTop)
{
//top=document.documentElement.scrollTop;
//left=document.documentElement.scrollLeft;
if (!isNaN(document.documentElement.scrollTop)) {
el.style.top = (hWindow + document.documentElement.scrollTop - tValue) +"px";
}
//console.log('documentElement: '+ document.documentElement.scrollTop);
}
//el.style.top = (document.documentElement.scrollTop + 10)+"px";
}
}
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值