0
点赞
收藏
分享

微信扫一扫

吸顶及显示隐藏

鱼板番茄 2022-01-04 阅读 79

吸顶

  • 事先为window开启滚动事件, 获取当前滚动高度
mounted(){
	window.onscroll = () => {
		this.add();
	};
},
method(){
	add(){
		let body = document.body;
		let html = document.documentElement;
		let ht = body || html;
		this.top = ht.scrollTop;
		}
}
  • 监听高度变化, 判断按钮的显示隐藏
watch: {
	top(newval, oldval) {
		if(newval > 200) {
			this.show = true;
		} else {
			this.show = false;
		}
	}
}
  • 点击返回头部
goskip(){
	window.scroll({top: 0, behavior: 'smooth'});
}

弹出隐藏

  • 设置show为false,点击为true即可
举报

相关推荐

0 条评论