赞
踩
踩坑:body、html的高度不能设置为100%,不然监听scroll事件无法生效
window.addEventListener('scroll', () => { let scrollTop = document.documentElement.scrollTop || document.body.scrollTop let windowHeight = document.documentElement.clientHeight || document.body.clientHeight let scrollHeight = document.documentElement.scrollHeight || document.body.scrollHeight if (scrollTop + windowHeight == scrollHeight) { //加载下一页数据 //判断是否存在下一页数据 const totalPage = Math.ceil(tableState.value.total / tableState.value.pagination.pageSize) if (tableState.value.pagination.currentPage <= totalPage){ debounceFn() } } if (scrollTop >= 400) { goTop.style.display = 'block' } else { goTop.style.display = 'none' } goTop.onclick = ()=>{ document.body.scrollTop = 0 document.documentElement.scrollTop = 0 } })
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。