1、获取窗口的位置,窗口相对于屏幕左边和上边的位置
IE和chrome 支持screenLeft、screenTop
ff、chrome支持screenX、screenY
跨浏览器兼容的写法
var x=typeof screenLeft=='number'?screenLeft:screenX;
var y=typeof screenTop=='number'?screenTop:screenY;
2、获取窗口大小
window.innerHeight;//得到页面高度
window.innerWidth;//得到页面宽度
window.outerHeight;//得到窗口高度+边框高度
window.outerWidth;//得到窗口宽度+边框宽度
对于IE的标准模式来说获取页面宽度和高度的方法
document.documentElement.clientHeight
document.documentElement.clientWidth;
对于IE6的非标准模式
document.body.clientHeight;
document.body.clientWidth;
// 跨浏览器的兼容写法
var width=window.innerWidth;
var height=window.innerHeight;
if(typeof width!=='number'){
if(document.compatMode=='CSS1compat'){//如果是,则是IE的标准模式
width=document.documentElement.clientWidth;
height=document.documentElement.clientHeight;
}else{//不是,则说明是ie的非标准模式
width=document.body.clientWidth;
height=document.body.clientHeight;
}
}