浏览器支持getBoundingClientRect的width和height属性?

Bry*_*eld 9 javascript dom cross-browser getboundingclientrect

我刚刚发现并且非常喜欢,getBoundingClientRect因为它包含子像素精度.这使我能够创建一致的对齐,即使用户键入Ctrl+Ctrl+ -.

它具有的属性top,bottom,left,right,& &.widthheight

这是简单的找到在互联网上的浏览器的支持,但没有这么多的的widthheight特别的属性.看来这是事后添加的.它适用于Firefox,Chrome和IE10,但是IE8和IE9呢?我不能方便地测试这些.

dan*_*vis 9

在IE9中作为IE8:

document.body.getBoundingClientRect() 
[object] {
    right : 2556,
    top : 0,
    bottom : 1195,
    left : 0
} 
Run Code Online (Sandbox Code Playgroud)

在IE9中作为IE9:

document.body.getBoundingClientRect() 
[object ClientRect] {
    bottom : 1435,
    height : 1435,
    left : 0,
    right : 2544,
    top : 0,
    width : 2544
} 
Run Code Online (Sandbox Code Playgroud)

所以,我会在IE9上说是,在IE8上没有...

  • IE 7也不支持宽度和高度.感谢微软的janky编程经验! (2认同)