Quantcast
Channel: MEPO Forum - 程式設計
Viewing all articles
Browse latest Browse all 99

Browser 的 JavaScript - clientWidth 及 scrollWidth (no replies)

$
0
0
我們來看下面這段程式片段(修改自TQC Javascript 203題)

<title>圖片捲動控制</title> <div id="dv" onmousedown="stop()" onmouseup="cont()" ondragend="contD()" style="white-space:nowrap"> </div>")
(1)請注意,div 有一個 屬性:style="white-space:nowrap"
也就是div的內容如果超過視窗(可視)寬度,他會在同一行繼續排下去,實際寬度會超過視窗,不會跳行

(2) 這時,有趣的一些 property來了(在我的19吋螢幕上測試),下面這些屬性以 alert 輸出:

(2-1)
在IE9.0.8112.16421中

document.body.clientWidth ( 或 document.getElementById('bd').clientWidth ) 的結果為 1419
document.body.scrollWidth ( 或 document.getElementById('bd').scrollWidth ) 的結果為 1700

(2-2)
在 FireFox 14.0.1中

(2-2-1)
初次執行
document.body.clientWidth ( 或 document.getElementById('bd').clientWidth ) 的結果為 1440
document.body.scrollWidth ( 或 document.getElementById('bd').scrollWidth ) 的結果為 1440

(2-2-2)
但在上面執行後,再按重新整理

document.body.clientWidth ( 或 document.getElementById('bd').clientWidth ) 的結果為 1440
document.body.scrollWidth ( 或 document.getElementById('bd').scrollWidth ) 的結果為 1700



只是按重新整理,會差這麼多,這算是 firefox 的 bug 嗎?

Viewing all articles
Browse latest Browse all 99

Trending Articles