JS和JQuery获取网页规格方法一览

2017-02-13  本文已影响26人  Separes
  1. 网页可见区域宽和高:

     document.documentElement.clientWidth;(不含边框)
     document.documentElement.clientHeight;(不含边框)
    

或:

    document.documentElement.offsetWidth;(包含边框)
    document.documentElement.offsetHeight;(包含边框)
  1. 网页可见区域宽和高(JQuery):
    $(window).width();
    $(window).height();

  2. 网页可见区域宽和高(包括边线):
    document.body.offsetWidth;
    document.body.offsetHeight;

  3. 滚动条的规格(JQuery):

滚动条到顶部的距离:

    $(document).scrollTop();

滚动条到左边的距离:

    $(document).scrollLeft();
  1. 网页正文全文高和宽:
    document.documentElement.scrollWidth;
    document.documentElement.scrollHeight;
    或:
    document.body.scrollWidth;
    document.body.scrollHeight;
    其中body宽度默认未设置;

  2. 网页文档高和宽(JQuery):
    $(document).width();
    $(document).height();
    或(获取body规格):
    $(document.body).width();
    $(document.body).height();

  3. 当前屏幕分辨率的规格:
    window.screen.height;
    window.screen.width;

  4. 屏幕可用区域规格:
    window.screen.availHeight;
    window.screen.availWidth;

  5. 当前屏幕设置:
    色位:
    window.screen.colorDepth;
    像素/英寸:
    window.screen.deviceXDPI;

  6. 获取或设置元素的规格:
    $(obj).width();
    $(obj).height();

注:根据W3C标准的不同,方法获取的内容可能会产生差异,详细请调试;
IE6下部分方法会产生较大偏差;

上一篇下一篇

猜你喜欢

热点阅读