如何获取HTML的高度

html-css064

如何获取HTML的高度,第1张

用这个方法:getComputedStyle() ,用法:getComputedStyle(obj)['height']

这个东西有不兼容IE8及其以下版本,这些版本的IE没有这方法,它们用的是currentStyle,所以,兼容写法:

function getStyle(obj, name) {

return window.getComputedStyle?getComputedStyle(obj, null)[name]:obj.currentStyle[name]

}

width_screen=screen.width // 获取宽度

height_screen=screen.height 高度

availWidth_screen=screen.availWidth

availHeight_screen=screen.availHeight

colorDepth_screen=screen.colorDepth

如果是动态获取的话,就自己写一个方法什么的给封装一下,然后加载。