📜  HTML | DOM getBoundingClientRect() 方法

📅  最后修改于: 2022-05-13 01:55:55.279000             🧑  作者: Mango

HTML | DOM getBoundingClientRect() 方法

HTML DOM getBoundingClientRect() 方法返回视口的相对定位。
它返回八个属性:左、上、右、下、x、y、宽度、高度。
滚动将改变位置值。

句法:

var rect = div.getBoundingClientRect();

例子:



  

    
        HTML | DOM getBoundingClientRect() Method
    
    

  

    
    
           
               Use scrollbar to change the position.         
        
        
    
    
     

输出:
点击前:

点击后:

支持的浏览器:

  • 铬 1.0
  • 浏览器 9.0
  • 火狐 3.0
  • 歌剧 9.5
  • Safari 4.0