美文网首页
vue 动态获取可视区高度

vue 动态获取可视区高度

作者: 良品山核桃 | 来源:发表于2019-01-08 16:44 被阅读0次

个人学习笔记

<div class="allposition_qw_content" ref="qwcontent" ></div>
data() {

            fullHeight: '' ";//fullHeight: document.documentElement.clientHeight  屏幕高度 默认值

        }

    },

methods: {

        changeFixed(fullHeight){                        //动态修改样式

            this.$refs.qwcontent.style.height =( 0.91*fullHeight - 200)+'px';

        }

    },

mounted() {

      this.fullHeight= `${document.documentElement.clientHeight}`;//默认值

      const that = this

      window.onresize = () => {

        return (() => {

          window.fullHeight = document.documentElement.clientHeigh

          that.fullHeight = window.fullHeight

        })()

      }

    },

watch: {

      // 如果 `fullHeight ` 发生改变,这个函数就会运行 

      fullHeight :function(val) {

        if(!this.timer) {

          this.fullHeight = val

          this.changeFixed(this.fullHeight)

          console.log(val)

          this.timer = true

          let that = this

          setTimeout(function (){//频繁触发 resize 函数,会导致页面很卡

            that.timer = false

          },100)

        }

      }

    }

相关文章

网友评论

      本文标题:vue 动态获取可视区高度

      本文链接:https://www.haomeiwen.com/subject/bjhbrqtx.html