今天做页面的时候遇到的问题,记录一下,作为下次制作的参考,直接贴代码(项目是用vue做的,只贴关键代码)
methods:{ move(){ var scrollTop = document.body.scrollTop;//距离顶部的高度 var clientHeight=document.body.clientHeight;//可视区域高度 var scrollHeight=document.body.scrollHeight;//滚动条整体高度 var bottom=scrollHeight-(scrollTop+clientHeight);//距离底部的位置 if(bottom==0){ console.log("快到底部了");//这里进行事件处理 } } }, computed: { filter: function() { var items = this.lists; for (var i = 0; i < items.length; i++) { if (items[i].msg == '筛选' && items[i].checked == true) { this.showFilter = true; } } return this.showFilter }, }, watch: { }, mounted(){ window.addEventListener('scroll',this.move) }原理嘛,就是滚动条的总高度等于距离顶部的滚动距离加上可视窗口的距离把