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
  • 相关阅读:
    新博客
    【Gym-100712 #H】Bridges
    【CodeForces817F】MEX Queries
    【POJ1734】Sightseeing trip
    【Aizu2968】Non-trivial Common Divisor
    【Gym-101473 #I】Patches
    【POJ2228】Naptime
    【CodeForces219D】Choosing Capital for Treeland
    【URAL1018】Binary Apple Tree
    深入探索C++对象模型(五)
  • 原文地址:https://www.cnblogs.com/lhl66/p/7908133.html
Copyright © 2011-2022 走看看