下面Javascript是获取控件在运行时于屏幕中的位置:
你可以复制以下Javascript代码:
function GetScreenPosition(object) { var position = {}; position.x = object.offsetLeft; position.y = object.offsetTop; while (object.offsetParent) { position.x = position.x + object.offsetParent.offsetLeft; position.y = position.y + object.offsetParent.offsetTop; if (object == document.getElementsByTagName("body")[0]) { break; } else { object = object.offsetParent; } } return position; }
View Code
好,我们来演示一下:
有站点中,创建一个网页,参考下图代码: