JavaScript/元素位置:修订间差异
来自康健生活
| 第50行: | 第50行: | ||
} | } | ||
</syntaxhighlight> | </syntaxhighlight> | ||
== 视窗 == | |||
<syntaxhighlight lang="javascript"> | |||
function getViewportSize(w){ | |||
//使用指定窗口,如果不带参数则使用当前窗口 | |||
w = w || window; | |||
if(w.innerWidth != null) | |||
return { w: w.innerWidth, h: w.innerHeight }; | |||
var d = w.document; | |||
//标准模式 | |||
if(document.compatMode == "CSS1Compat") | |||
return { w: d.documentElement.clientWidth, h: d.cocumentElement.clientHeight }; | |||
//怪异模式 | |||
return { w: d.body.clientWidth, h: d.body.clientHeight } | |||
}</syntaxhighlight> | |||