使用js获取页面的各种高度

使用js获取相关高度:

  获取网页被滚动条卷去的高度——兼容写法:

    scrollHeight = documen.body.scrollTop || document.documentElement.scrollTop;

  获取网页全文的高度——兼容写法:

    windowHeight = document.body.scrollHeight || document.documentElement.scrollHeight;

  获取网页可视区域的高度——兼容写法:

    screenHeight = document.body.clientHeight || document.documentElement.clientHeight;

  获取某个元素的高度——利用DOM对象的属性http://www.w3school.com.cn/jsref/dom_obj_all.asp

    domHeight = domElement.offsetHeight(包括border和padding)

使用jq获取相关高度:

  获取网页被滚动条卷去的高度:

    scrollHeight = $(window).scrollTop();

  获取网页全文的高度——兼容写法:

    windowHeight = $(document).height();

  获取网页可视区域的高度——兼容写法:

    screenHeight = $(window).height();

  获取某个元素的高度——利用DOM对象的属性:

    domHeight = domElement.height();

原文地址:https://www.cnblogs.com/goforwards/p/8455773.html