`

ie 怪异模式下 position fixed javascript 实现

阅读更多
<!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";
	}
}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics