首页 > 其他 > 详细

getBoundingClientRect介绍

时间:2019-07-05 23:33:07      阅读:113      评论:0      收藏:0      [点我收藏+]

getBoundingClientRect用于获取元素相对与浏览器视口的位置
由于getBoundingClientRect()已经是w3c标准,所以不用担心兼容,不过在ie下还是有所区别

{
    top: '元素顶部相对于视口顶部的距离',
    bottom: '元素底部相对于视口顶部的距离',
    left: '元素左边相对于视口左边的距离',
    right: '元素右边相对于视口左边的距离',
    height: '元素高度',
    width: '元素宽度'
}
// 兼容写法
function getClientReat(client) {
    const { top, bottom, left, right, height, width } = client.getBoundingClientRect()
    return {
        top,
        bottom,
        left,
        right,
        height: height || bottom - top,
        width:    width || right - left
    }
}

转载自:https://segmentfault.com/a/1190000016815362

getBoundingClientRect介绍

原文:https://www.cnblogs.com/smart-girl/p/11138791.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!