我的是:<!DOCTYPE html>
博客園:<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
關(guān)于HTML文檔類型參考:http://i.wanz.im/2010/05/28/why_doctype_html/
檢查發(fā)現(xiàn)JS在獲取當(dāng)前頁面可視大小,和頁面滾動(dòng)位置有差別!
在頁面包含一個(gè)2000*2000的DIV是IE和Chrome在不同HTML文檔類型測試整理數(shù)據(jù)如下:
標(biāo)準(zhǔn):<!DOCTYPE html>
特殊:<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
當(dāng)HTML中未添加HTML文檔類型時(shí),默認(rèn)為特殊模式!
Chrome標(biāo)準(zhǔn) | Chrome特殊 | IE標(biāo)準(zhǔn) | IE特殊 | |
document.body.clientTop; | 0 | 0 | 0 | 2 |
document.body.clientLeft; | 0 | 0 | 0 | 2 |
document.body.clientWidth; | 473 | 473 | 471 | 471 |
document.body.clientHeight; | 2000 | 625 | 2000 | 604 |
document.body.scrollTop; | 224 | 289 | 0 | 255 |
document.body.scrollLeft; | 315 | 388 | 0 | 278 |
document.body.scrollWidth; | 2005 | 2005 | 2005 | 2010 |
document.body.scrollHeight; | 2010 | 2010 | 2000 | 2005 |
document.body.offsetTop; | 0 | 0 | 0 | 0 |
document.body.offsetLeft; | 0 | 0 | 0 | 0 |
document.body.offsetWidth; | 473 | 473 | 471 | 492 |
document.body.offsetHeight; | 2000 | 2000 | 2000 | 625 |
document.documentElement.clientTop; | 0 | 0 | 0 | 0 |
document.documentElement.clientLeft; | 0 | 0 | 0 | 0 |
document.documentElement.clientWidth; | 473 | 473 | 471 | 0 |
document.documentElement.clientHeight; | 625 | 2010 | 604 | 0 |
document.documentElement.scrollTop; | 0 | 0 | 199 | 0 |
document.documentElement.scrollLeft; | 0 | 0 | 241 | 0 |
document.documentElement.scrollWidth; | 2005 | 2005 | 2005 | 492 |
document.documentElement.scrollHeight; | 2010 | 2010 | 2010 | 625 |
document.documentElement.offsetTop; | 0 | 0 | 0 | 0 |
document.documentElement.offsetLeft; | 0 | 0 | 0 | 0 |
document.documentElement.offsetWidth; | 473 | 473 | 492 | 492 |
document.documentElement.offsetHeight; | 2010 | 2010 | 625 | 625 |
分析:
頁面總寬度:document.body.scrollWidth;
頁面總高度:document.body.scrollHeight;
Chrome頁面位置:document.body.scrollTop; document.body.scrollLeft;
Chrome標(biāo)準(zhǔn)頁面可視區(qū)域:document.documentElement.clientWidth; document.documentElement.clientHeight;
Chrome特殊頁面可視區(qū)域:document.body.clientWidth; document.body.clientHeight;
IE標(biāo)準(zhǔn)頁面位置:document.documentElement.scrollTop; document.documentElement.scrollLeft;
IE標(biāo)準(zhǔn)頁面可視區(qū)域:document.documentElement.clientWidth; document.documentElement.clientHeight;
IE特殊頁面位置:document.body.scrollTop; document.body.scrollLeft;
IE特殊頁面可視區(qū)域:document.body.clientWidth; document.body.clientHeight;
JS代碼如下:
標(biāo)簽:濟(jì)寧 ???/a> 寧夏 贛州 延安 衡水 寧波 日照
巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《HTML文檔類型詳解 推薦》,本文關(guān)鍵詞 HTML,文檔,類型,詳解,推薦,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。