动态获取屏幕的宽度

来源:互联网 发布:青少年犯罪率数据2016 编辑:程序博客网 时间:2024/06/06 15:49
           //获取屏幕的分辨率           var iwidth=window.screen.availWidth;                // alert(iwidth)           //动态的获取滚动条的宽度(不同的电脑的分辨率不同,其对应的滚动条的宽度也是不同的,这边可以动态获取滚动条的宽度)           function getScrollWidth() {             var noScroll, scroll, oDiv = document.createElement("DIV");             oDiv.style.cssText = "position:absolute; top:-1000px; width:100px; height:100px; overflow:hidden;";            noScroll = document.body.appendChild(oDiv).clientWidth;                    oDiv.style.overflowY = "scroll";                    scroll = oDiv.clientWidth;                    document.body.removeChild(oDiv);                    return noScroll-scroll;                  }      //这里可以获取屏幕可视区域的宽度  var width=iwidth-getScrollWidth();
原创粉丝点击