简体   繁体   English

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

[英]Browser support of width and height properties of getBoundingClientRect?

I just discovered and really like getBoundingClientRect because it includes sub-pixel precision. 我刚刚发现并且非常喜欢getBoundingClientRect因为它包含子像素精度。 This has allowed me to create consistent alignment, even if the user types Ctrl + or Ctrl + - . 这使我可以创建一致的对齐,即使用户键入Ctrl +Ctrl + -

It has properties top , bottom , left , right , & width & height . 它具有topbottomleftrightwidthheight属性。

It is simple to find the browser support on the internet, but not so much for the the width and height properties in particular. 在互联网上找到浏览器支持很简单,但对于widthheight属性尤其如此。 It appears that this was added after the fact. 看来这是事后补充的。 It works in Firefox, Chrome, and IE10, but what about IE8 & IE9? 它适用于Firefox,Chrome和IE10,但是IE8和IE9呢? I can't test these conveniently. 我不能方便地测试这些。

In IE9 as IE8: 在IE9中作为IE8:

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

In IE9 as IE9: 在IE9中作为IE9:

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

So, I'd say yes on IE9, no on IE8... 所以,我会在IE9上说是,在IE8上没有...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM