1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > js 监听页面滚动到底部 监听可视区域滚动到底部

js 监听页面滚动到底部 监听可视区域滚动到底部

时间:2019-06-22 23:43:51

相关推荐

js 监听页面滚动到底部 监听可视区域滚动到底部

全局页面body上的底部监听:

window.onscroll = function(){var scrollTop = document.documentElement.scrollTop||document.body.scrollTop;var windowHeight = document.documentElement.clientHeight || document.body.clientHeight;var scrollHeight = document.documentElement.scrollHeight||document.body.scrollHeight;if(scrollTop+windowHeight>=scrollHeight){ //考虑到滚动的位置一般可能会大于一点可滚动的高度,所以这里不能用等于console.log("距顶部"+scrollTop+"可视区高度"+windowHeight+"滚动条总高度"+scrollHeight);} }

局部可视区域的滚动到底部(vue版本代码):

<div style="flex:1;overflow-y:auto;" @scroll="scrollEvent">内容</div>

methods: {// 滚定监听scrollEvent(e) {// console.log('滚动',e.currentTarget.scrollTop,e.currentTarget.clientHeight,e.currentTarget.scrollHeight);if (Math.ceil(e.currentTarget.scrollTop + e.currentTarget.clientHeight) >=e.currentTarget.scrollHeight) { //容差:20px// console.log('滚动到底部');this.$emit('scrollBottom');}}},

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。