美文网首页工作生活
getBoundingClientRect()

getBoundingClientRect()

作者: 糕糕AA | 来源:发表于2019-07-02 20:04 被阅读0次

    用于获取某个元素相对于视窗的位置集合。集合中有top, right, bottom, left等属性。

    1. 语法:这个方法没有参数。
    2. 返回值类型:TextRectangle对象,每个矩形具有四个整数性质( 上, 右 , 下,和左 )表示的坐标的矩形,以像素为单位。
      • rectObject.top:元素上边到视窗上边的距离;
      • rectObject.right:元素右边到视窗左边的距离;
      • rectObject.bottom:元素下边到视窗上边的距离;
      • rectObject.left:元素左边到视窗左边的距离;
      • ⚠️
      • Element.getBoundingClientRect().width =  border-left-width + padding-left + width + padding-right + border-right-width
        
        Element.getBoundingClientRect().height =  border-top-width + padding-top + height + padding-bottom + border-bottom-width
        

    相关文章

      网友评论

        本文标题:getBoundingClientRect()

        本文链接:https://www.haomeiwen.com/subject/iwathctx.html