vue 监听可视区域的高度变化
data(){height: document.body.clientHeight - 67,timer: false}mounted() {const that = thiswindow.onresize = () => {return (() => {window.screenHeight = document.body.clientHeightthat.height = wind
·
data(){
height: document.body.clientHeight - 67,
timer: false
}
mounted() {
const that = this
window.onresize = () => {
return (() => {
window.screenHeight = document.body.clientHeight
that.height = window.screenHeight - 67;
})()
}
},
watch: {
height(val) {
// 为了避免频繁触发resize函数导致页面卡顿,使用定时器
if (!this.timer) {
// 一旦监听到的screenWidth值改变,就将其重新赋给data里的screenWidth
this.screenHeight = val
this.timer = true
let that = this
setTimeout(function() {
that.timer = false
}, 400)
}
}
},
更多推荐
已为社区贡献2条内容
所有评论(0)