`
xiangzhengyan
  • 浏览: 124674 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

element绝对位置

    博客分类:
  • js
阅读更多
自己写的以及prototype.js中提供的方法,向上循环计算,在层次复杂的时候都计算不对
而my97的弹出的日期选择框,目前没发现问题,抽取如下,有空再整理

var pos = C(el);
//------------
function C (el) {
		
		var
		// F = $dp.position.left,
		// B = $dp.position.top,
		G = el.getBoundingClientRect(), $ = {
			"leftM" : 0,
			"topM" : 0
		},
		C = M(), 
		A = Y();
		// D = $dp.dd.offsetHeight,
		// _ = $dp.dd.offsetWidth;

		var B = A.top + $.topM + G.bottom;
		B += -1;

		var F = A.left + Math.min($.leftM + G.left, C.width - 5) - 2;

		return {
			top: B ,
			left: F
		}
	}

function M() {
		var _ = window["document"];
		_ = _["documentElement"] && _["documentElement"].clientHeight
			&& _["documentElement"].clientHeight <= _.body.clientHeight
			? _["documentElement"]
			: _.body;
		return {
			"width" : _.clientWidth,
			"height" : _.clientHeight
		};
	}

function() Y{
		var B = window["document"], 
		A = B["documentElement"], _ = B.body;
		B = (A && A.scrollTop != null && (A.scrollTop > _.scrollLeft || A.scrollLeft > _.scrollLeft))
			? A
			: _;
		return {
			"top" : B.scrollTop,
			"left" : B.scrollLeft
		};
	}




分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics