• 网页尺寸


    1,scrollHeight

    一、针对IE、Opera:

    scrollHeight 是网页内容实际高度,可以小于 clientHeight。

    二、针对NS、FF:

    scrollHeight 是网页内容高度,不过最小值是 clientHeight。也就是说网页内容实际高度小于 clientHeight 时,scrollHeight 返回 clientHeight 。

    三、浏览器兼容性

    var w=document.documentElement.scrollWidth
       || document.body.scrollWidth;
    var h=document.documentElement.scrollHeight
       || document.body.scrollHeight;
    scrollHeight和scrollWidth还可获取Dom元素中内容实际占用的高度和宽度。
    documentElement获取的是整个HTML元素他会打印出完整的HTML结构出来
    body获取的是当前页面的body元素
    clientHeight 获取的是 body对象高度 但不包括边框线
    offsetHeight获取的是网页可见高度,包括边框线
    scrollHeight获取的是网页全文,正文的高度


    document.documentElement 整根节点,既<html>
    document.body 是DOM里的body子节点,既<body>
    要注意‘高’是Html内容的高还是浏览器可视窗口的高!内容的高是随着内容的增减而改变的,宽说是因为有些内容是占据一行的,所以是稳定不变。另外Html文档内容默认是有margin值的!可以在css中*{margin:0}清除margin值
    2,offsetHeight

    一。
    offsetHeight和offsetWidth,获取网页内容高度和宽度(包括滚动条等边线,会随窗口的显示大小改变)。
    offsetHeight = clientHeight + 滚动条 + 边框。
    二。浏览器兼容性:
    var w= document.documentElement.offsetWidth || document.body.offsetWidth;
    var h= document.documentElement.offsetHeight || document.body.offsetHeight;
  • 相关阅读:
    Springboot + Mybatis 多数据源配置
    构建微服务:Spring boot 入门篇
    IDEA SpringBoot代码修改热部署/加载
    vue-cli知识点
    vuex知识点
    正则基本知识
    多行SQL语句拼成一条数据
    软件的版本控制
    ASP.NET 表单验证实现浅析
    建造者模式
  • 原文地址:https://www.cnblogs.com/monica123456/p/6474882.html
Copyright © 2020-2023  润新知