function getBoundingClientRect(element){ var scrollTop = document.documentElement.scrollTop var scrollLeft = document.documentElement.scrollLeft if(element.getBoundingClientRect){ if(typeof arguments.callee.offset != "number"){ var temp = document.createElement("div") temp.style.cssText = "position:absolute;left:0;top:0" document.body.appendChild(temp) arguments.callee.offset = -temp.getBoundingClientRect().top - scrollTop document.body.removeChild(temp) temp = null } var rect = element.getBoundingClientRect() var offset = arguments.callee.offset return { left: rect.left + offset, right: rect.right + offset, top: rect.top + offset, bottom: rect.bottom + offset } } else { var actualLeft = getElementLeft(element) var actualTop = getElementTop(element) return { left: actualLeft - scrollLeft, right: actualLeft + element.offsetWidth - scrollLeft, top: actualTop - scrollTop, bottom: actualTop + element.offsetHeight - scrollTop } } }
原文地址:https://www.cnblogs.com/hanxiaoer/p/11551796.html
时间: 2024-10-13 16:14:10