zoukankan      html  css  js  c++  java
  • vue获取dom元素高度的方法

    获取高度:

    <div ref="自定义名称" >

    </div>
    要在钩子mounted里面dom结构生成后去获取dom的高度,宽度,修改样式等操作!!!
     mounted() {
        let h = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight; //浏览器高度
        let topH = this.$refs.topInfo.offsetHeight;
        console.log()
        let tabH = this.$refs.tab.offsetHeight;
        console.log()
        let subH = this.$refs.subBtn.offsetHeight;
        console.log()
        let scrollHight = this.$refs.scroller.offsetHeight
        this.height = (h - topH - tabH - subH) + "px"
        //localStorage.setItem("access_token", '52ecda6ecb4a11e7bd2a00163e0891fd') //测试token
        this.queryData(0)
        let w = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;//浏览器宽度  
    
      }   //获取dom元素高度通过在标签里面定义ref属性,用this.$refs.自定义名称.offsetHight;去获取。

    还有其他获取指定高度的方式:

    //获取元素样式值,为元素ref="ele"(在样式里面写死了的高度)
    var heightCss = window.getComputedStyle(this.$refs.ele).height; // ?px

    //获取元素内联样式值 var heightStyle =this.$refs.ele.style.height; // ?px
  • 相关阅读:
    驱动_spi驱动框架
    代码示例_陀螺仪_I2C
    控制台查看 pip 版本的指令
    更新升级(upgrade) pip 出错问题解决
    105. 从前序和中序遍历序列构造二叉树
    TCP初步了解
    Java GUI 之 JSplitPane
    URL的含义
    JPanel与JFrame的关系
    IDEA禁用函数名拼写错误提示
  • 原文地址:https://www.cnblogs.com/lhl66/p/7908133.html
Copyright © 2011-2022 走看看