在某個點上彈出層

weixin_30588675發表於2020-04-05
 <script type="text/javascript">

function showUserInfo(obj) {
var authort;
var point = absolutePoint(obj);
var div = document.getElementById('divshow');
div.style.position = 'absolute';
div.style.left = point.x + 127 + "px";
div.style.top = point.y + "px";
div.style.display = 'block';

authort = setTimeout("document.getElementById('divshow').style.display = 'block';", 100);
if (!div.onmouseover) {
div.onmouseover = function() {
div.style.display = 'block';
}
div.onmouseout = function() {
div.style.display = 'none';
}
}
if (!obj.onmouseout) {
obj.onmouseout = function() {
clearTimeout(authort);
}
}
}

function closeCard() {
var div = document.getElementById('divshow');
div.style.display = 'none';
}


/// <summary>
/// 獲得元素的絕對座標
/// </summary>
/// <param name="element">HTML元素</param>
function absolutePoint(element) {
var result = { x: element.offsetLeft, y: element.offsetTop };
element = element.offsetParent;
while (element) {
result.x += element.offsetLeft;
result.y += element.offsetTop;
element = element.offsetParent;
}
return result;
}
</script>

轉載於:https://www.cnblogs.com/jonhson/archive/2011/10/09/2204064.html

相關文章