欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

由document.body和document.documentElement想到的

 更新時間:2009年04月13日 10:16:48   作者:  
不知道大家對這個標題有沒有想法,反正此前我一直把他們混為了一談。其實不然,首先需有個“標準”的概念。
對于document.compatMode,很多朋友可能都根我一樣很少接觸,知道他的存在卻不清楚他的用途。其實這個對于我們開發(fā)兼容性的web頁面還是很有幫助,我們都知道,盒模型的渲染在 Standards Mode和Quirks Mode是有很大差別的,在不聲明Doctype的情況下,瀏覽器默認是Quirks Mode。所以為兼容性考慮,我們可能需要獲取當前的文檔渲染方式。
document.compatMode正好派上用場,它有兩種可能的返回值:BackCompat和CSS1Compat,對其解釋如下:
BackCompat Standards-compliant mode is not switched on. (Quirks Mode)
CSS1Compat Standards-compliant mode is switched on. (Standards Mode)
當文檔有了標準聲明時, document.compatMode 的值就等于 "CSS1compat", 因此, 我們可以根據(jù) document.compatMode 的值來判斷文檔是否加了標準聲明
var height = document.compatMode=="CSS1Compat" ? document.documentElement.clientHeight : document.body.clientHeight;
當文檔有了標準聲明時火狐的style.top等等的設(shè)置必須加上“px”等單位,否則它不會認。既然已經(jīng)說道了這,再展開一下。對于火狐:
一、offsetTop 返回的是數(shù)字,而 style.top 返回的是字符串,除了數(shù)字外還帶有單位:px。
二、offsetTop 只讀,而 style.top 可讀寫。
三、如果沒有給 HTML 元素指定過 top 樣式(即使在css中設(shè)定也不行),則 style.top 返回的是空字符串。
offsetLeft 與 style.left、offsetWidth 與 style.width、offsetHeight 與 style.height 也是同樣道理。
再說說他們的區(qū)別吧:
下面這段大家可能都見到過,在網(wǎng)上被轉(zhuǎn)載過很多次,在這我也借用一下:
.Kfk428 { display:none; }
網(wǎng)頁可見區(qū)域?qū)挘?document.body.clientWidth;
網(wǎng)頁可見區(qū)域高: document.body.clientHeight;
網(wǎng)頁可見區(qū)域?qū)挘?document.body.offsetWidth (包括邊線的寬);
網(wǎng)頁可見區(qū)域高: document.body.offsetHeight (包括邊線的寬);
網(wǎng)頁正文全文寬: document.body.scrollWidth;
網(wǎng)頁正文全文高: document.body.scrollHeight;
網(wǎng)頁被卷去的高: document.body.scrollTop;
網(wǎng)頁被卷去的左: document.body.scrollLeft;
網(wǎng)頁正文部分上: window.screenTop;
網(wǎng)頁正文部分左: window.screenLeft;
屏幕分辨率的高: window.screen.height;
屏幕分辨率的寬: window.screen.width;
屏幕可用工作區(qū)高度: window.screen.availHeight;
屏幕可用工作區(qū)寬度:window.screen.availWidth;

scrollHeight: 獲取對象的滾動高度。
scrollLeft:設(shè)置或獲取位于對象左邊界和窗口中目前可見內(nèi)容的最左端之間的距離
scrollTop:設(shè)置或獲取位于對象最頂端和窗口中可見內(nèi)容的最頂端之間的距離
scrollWidth:獲取對象的滾動寬度
offsetHeight:獲取對象相對于版面或由父坐標 offsetParent 屬性指定的父坐標的高度
offsetLeft:獲取對象相對于版面或由 offsetParent 屬性指定的父坐標的計算左側(cè)位置
offsetTop:獲取對象相對于版面或由 offsetTop 屬性指定的父坐標的計算頂端位置
event.clientX 相對文檔的水平座標
event.clientY 相對文檔的垂直座標

event.offsetX 相對容器的水平坐標
event.offsetY 相對容器的垂直坐標
document.documentElement.scrollTop 垂直方向滾動的值
event.clientX+document.documentElement.scrollTop 相對文檔的水平座標+垂直方向滾動的量

以上主要指IE之中,F(xiàn)ireFox差異如下:
IE6.0、FF1.06+:
clientWidth = width + padding
clientHeight = height + padding
offsetWidth = width + padding + border
offsetHeight = height + padding + border
IE5.0/5.5:
clientWidth = width - border
clientHeight = height - border
offsetWidth = width
offsetHeight = height
(需要提一下:CSS中的margin屬性,與clientWidth、offsetWidth、clientHeight、offsetHeight均無關(guān))

在設(shè)置了文檔類型后也可能有差異,以上僅供參考

相關(guān)文章

最新評論