[note] Browser Coordinate System │ 瀏覽器座標系統
keywords: offset, layer, page, client, coordinate system, 位置
TL;DR
先想想:
- 這個數值是屬於相對某個點的距離、位置(例如,x, y, left, top, right, bottom);或是屬於大小尺寸(width、height)
- 這個數值包不包含 scrollbar
- 這個數值包不包含 browser 的工具列或網址列在內

圖片來源:Element size and scrolling @ javascript.info
- clientWidth/clientHeight 和 offsetWidth/offsetHeight 最大的差別在於「後者」除了同樣有 content 和 padding 之外,還多了 border、scrollbar 的寬高。
- scrollWidth/scrollHeight 是實際上內容的完成高度或寬度,包含了使用者需要捲動捲軸才能看到的部分。
offsetLeft/offsetTop:指游標到"容器"(offsetParent)左上角的偏移量(offsetParent.id)。client:指游標到 browser window 左上角的偏移量(不管 HTML document),滾動瀏覽器捲軸時,同樣位置座標相同。又稱visual viewport。page:指游標到 document 左上角的偏移量,滾動瀏覽器捲軸時,同樣位置座標不同,又稱作layout viewport。
示範程式碼與畫面 @ CodePen
HTMLElement
- Element size and scrolling @ JavaScript.info
- Layout and the containing block @ MDN