2007-05-29

[Note] Javascript Viewport and Document Height

當viewportHeight大於documentHeight時,IE的viewportHeight真的大於documentHeight,而FireFox的viewportHeight卻等於documentHeight。


var documentHeight;
if (document.documentElement && document.documentElement.scrollWidth) {
documentHeight = document.documentElement.scrollHeight;
} else if (document.body.scrollWidth) {
documentHeight = document.body.scrollHeight;
}
var viewportHeight;
if (window.innerWidth) {
// All browsers but IE
viewportHeight = window.innerHeight;
} else if (document.documentElement && document.documentElement.clientWidth) {
// These functions are for IE6 when there is a DOCTYPE
viewportHeight = document.documentElement.clientHeight;
} else if (document.body.clientWidth) {
// These are for IE4, IE5, and IE6 without a DOCTYPE
viewportHeight = document.body.clientHeight;
}

20120703 更新 - 用 jQuery 取得 Div 的寬度與高度(Width, Padding, Border, Margin)

沒有留言:

張貼留言