box model相關的API

HTML部分(值為數字):

alert(screen.availWidth);    顯示器的可用寬度,不包括任務欄
alert(screen.colorDepth);    顯示器顏色深度,主流是24,有的是32,把alpha也算進去了
alert(screen.pixelDepth);    基本上同上
alert(screen.width);        顯示器的寬度
alert(window.innerWidth);    瀏覽器窗口,用來顯示網頁的部分的寬度
alert(window.outerWidth);    瀏覽器窗口的寬度,包括工具欄,包括顯示器可視區域之外的部分
alert(window.pageXOffset);    瀏覽器窗口滾動的量,相當於documentElement.scrollLeft
alert(window.screenX);        瀏覽器窗口在顯示器中的位置,Firefox最大化時是-8,chrome为0
alert(ele.clientLeft);        對象的padding box相對於border box的左上角的位置,數字剛好就是border的值
alert(ele.clientWidth);        對象的padding box的寬度,不包括邊框和滾動條
alert(ele.offsetLeft);        對象相對於最近的定位祖先元素的位置
alert(ele.offsetParent);    對象的最近定位祖先元素
alert(ele.offsetWidth);        border box的寬度
alert(ele.scrollLeft);        對象滾動的量,可讀可寫,瀏覽器最外層的滾動條屬於HTML節點,而不是body節點(document.documentElement.scrollLeft)
alert(ele.scrollWidth);        對象的寬度,把滾動條的部分拉伸開
alert(e.screenX);        鼠標相對顯示器的位置
alert(e.clientX);        鼠標相對client area的位置(The client area is the current window.)
alert(e.pageX);            鼠標相對document的位置
alert(e.offsetX);        鼠標相對padding box的位置

Javascript部分:
document.elementFromPoint()    相對於..
ele.getBoundingClientRect()    相對於..
ele.scrollIntoView()        相當於anchor

 

CSS部分(值為n+"px"):

 

 

辨異:

一、alert(ele.clientLeft)與alert(e.clientX),兩者都提到client,但前者指padding box,作為要計算的對象,後者指client area,作為參照對象,後者也可以理解成document對象的padding box

二、alert(ele.offsetLeft)、ele.offsetWidth與alert(e.offsetX),三者都提到offset,但前者指最近定位元素,作為參照對象,次者指當前的padding box,作為要計算的對象,後者指當前的padding box,作為參照對象

三、alert(window.innerWidth)與alert(e.clientX),兩者都提到window,但是前者指瀏覽器這個軟件在OS中的UI窗口,作為要計算的對象,後者指瀏覽器用來展示網頁的部分,作為參照對象

posted @ 2015-10-06 23:01  嘯嘯生  阅读(150)  评论(0编辑  收藏  举报