zoukankan      html  css  js  c++  java
  • 常见Js获取高宽度的方法

    获取高宽度

    浏览器窗口可视区域大小  在不同浏览器都实用的 JavaScript 方案:

    var w= document.documentElement.clientWidth

    || document.body.clientWidth;

    var h= document.documentElement.clientHeight

    || document.body.clientHeight;

    网页尺寸scrollHeight

    var w=document.documentElement.scrollWidth

    || document.body.scrollWidth;

    var h=document.documentElement.scrollHeight

    || document.body.scrollHeight;

     

    网页可见区域宽:document.body.clientWidth

    网页可见区域高:document.body.clientHeight

    网页可见区域宽:document.body.offsetWidth (包括边线的宽)

    网页可见区域高:document.body.offsetHeight (包括边线的宽)

    网页正文全文宽:document.body.scrollWidth

    网页正文全文高:document.body.scrollHeight

    网页被卷去的高:document.body.scrollTop

    网页被卷去的左:document.body.scrollLeft

    网页正文部分上:window.screenTop

    网页正文部分左:window.screenLeft

    屏幕分辨率的高:window.screen.height

    屏幕分辨率的宽:window.screen.width

    屏幕可用工作区高度:window.screen.availHeight

    屏幕可用工作区宽度:window.screen.availWidth

    获取滚动条的高度:document.body.scrollTop

     
    jquery:
    $(document).height();

    Jquery

    alert($(window).height());//浏览器当前窗口可视区域高度

    alert($(document).height());//浏览器当前窗口文档的高度

    alert($(document.body).height());//浏览器当前窗口文档body的高度

    alert($(document.body).outerHeight(true));//浏览器当前窗口文档body的总高度 包括border padding margin

    alert($(window).width());//浏览器当前窗口可视区域宽度

    alert($(document).width());//浏览器当前窗口文档对象宽度

    alert($(document.body).width());//浏览器当前窗口文档body的宽度

    alert($(document.body).outerWidth(true));//浏览器当前窗口文档body的总宽度 包括border padding margin

     
     
     





  • 相关阅读:
    解决Uploadify 3.2上传控件加载导致的GET 404 Not Found问题
    Intellij idea的Dependencies波浪线
    Web.xml配置详解之context-param
    The superclass "javax.servlet.http.HttpServlet" was not found on the Java Build Path(Myeclipse添加Server Library)
    html5 video mp4播放不了问题
    切片优化小拾
    解决video标签的兼容性
    css module.css demo
    Gnet 响应式官网开发总结
    前端小总结
  • 原文地址:https://www.cnblogs.com/mmyh/p/7238271.html
Copyright © 2011-2022 走看看