<!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=gb2312" />
<title>获取元素绝对位置</title>
<script type="text/javascript">
window.onload = function () {
alert(rePos(document.getElementById('s')).y);
};var rePos = function () {
return document.documentElement.getBoundingClientRect && function (o) {
var pos = o.getBoundingClientRect(), root = o.ownerDocument || o.document;
return { x : pos.left + root.documentElement.scrollLeft, y : pos.top + root.documentElement.scrollTop };
} || function (o) {
var x = 0, y = 0;
do { x += o.offsetLeft, y += o.offsetTop; } while (o = o.offsetParent);
return { 'x' : x, 'y' : y };
};
}();
</script>
</head><body>
<div style="height:1000px;"> </div>
<table>
<tr><td> </td></tr>
<tr><td bgcolor="#000000";><div id="s"> </div></td></tr>
</table>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>获取元素绝对位置</title>
<script type="text/javascript">
window.onload = function () {
alert(rePos(document.getElementById('s')).y);
};var rePos = function () {
return document.documentElement.getBoundingClientRect && function (o) {
var pos = o.getBoundingClientRect(), root = o.ownerDocument || o.document;
return { x : pos.left + root.documentElement.scrollLeft, y : pos.top + root.documentElement.scrollTop };
} || function (o) {
var x = 0, y = 0;
do { x += o.offsetLeft, y += o.offsetTop; } while (o = o.offsetParent);
return { 'x' : x, 'y' : y };
};
}();
</script>
</head><body>
<div style="height:1000px;"> </div>
<table>
<tr><td> </td></tr>
<tr><td bgcolor="#000000";><div id="s"> </div></td></tr>
</table>
</body>
</html>
解决方案 »
- 几个jquery和javascript的问题
- JS 获取li 行高
- 关于span的disabled禁用属性
- 函数封装问题
- frame 如何把左边的选择的数据提交到右边的页面上?
- 我拷了如下一段代码,为什么在2000下正常,在XP下好象没执行?
- 妈哟,这是啥子 javascript 代码哟!!!
- 如何实现把Inputbox函数值在文本框里面显示出来
- 请问怎么样实现打印网页中指定的表格,而不是全页
- Jquery查找到TreeView节点后,让滚动条滚动到这个节点,怎么搞?
- 关于MZTREEVIEW2.0 控件中checkbox 的问题,我如何得到用户选中的值,怎样设置默认值?
- FCKEditor的InsertHtml方法如何防止自动转换为绝对路径?
你什么意思???