function getBoundingClientRect (element) { var rect = element.getBoundingClientRect(); // whether the IE version is lower than 11 var isIE = navigator.userAgent.indexOf('MSIE') != -1; // fix ie document bounding top always 0 bug var rectTop = isIE && element.tagName === 'HTML' ? -element.scrollTop : rect.top; return { left: rect.left, top: rectTop, right: rect.right, bottom: rect.bottom, width: rect.right - rect.left, height: rect.bottom - rectTop }; }
element.getBoundingClientRect();进行获取高度
最新推荐文章于 2024-10-16 08:45:00 发布
本文介绍了一个JavaScript函数,用于获取页面上指定元素的边界信息,包括左、顶、右、底的位置坐标及宽度和高度,并针对IE浏览器做了特殊处理。
2074

被折叠的 条评论
为什么被折叠?



