getBoundingClientRect()
對Javascript 中的函數感到困惑。
根據官方文檔,如果const rect = getBoundingClientRect();
,那麼我們有
rect.width = rect.right - rect.left;
rect.height = rect.bottom - rect.top;
這是否意味著左右位置是左包括右排,即[左,右)?否則應該是
rect.height = rect.bottom - rect.top + 1;
看看下面的5x5
地圖。在[inclusive, inclusive]
mode 中,所有 s 的邊界矩形1
應該是left=2, right=4, top=3, bottom=4
,我們有
width=right-left+1=4-2+1
height=bottom-top+1=4-3+1
5x5 網格
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 1 1 1
0 0 1 1 1
一個更具體的問題:
是什麼rect.left
意思?這是否意味著到客戶端容器或第i
th 像素左側的距離?怎麼樣rect.right
?
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句