Bry*_*eld 9 javascript dom cross-browser getboundingclientrect
我刚刚发现并且非常喜欢,getBoundingClientRect因为它包含子像素精度.这使我能够创建一致的对齐,即使用户键入Ctrl+或Ctrl+ -.
它具有的属性top,bottom,left,right,& &.widthheight
这是简单的找到在互联网上的浏览器的支持,但没有这么多的的width和height特别的属性.看来这是事后添加的.它适用于Firefox,Chrome和IE10,但是IE8和IE9呢?我不能方便地测试这些.
在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上没有...