且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

屏幕宽度与可见部分

更新时间:2023-01-04 13:33:42

function width(){
   return window.innerWidth 
       || document.documentElement.clientWidth 
       || document.body.clientWidth 
       || 0;
}

function height(){
   return window.innerHeight 
       || document.documentElement.clientHeight 
       || document.body.clientHeight 
       || 0;
}

使用它们返回 height()可见窗口的code>或 width()

JSFiddle示例。