javascript - js控制移动到底部触发
本文介绍了javascript - js控制移动到底部触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问 题
$(window).scroll(function () {
var scrollTop = $(this).scrollTop()
var windowHeight = $(this).height()
var scrollHeight = $(document).height()
console.log('-----------------------')
if((scrollTop+windowHeight)>scrollHeight){
console.log('bottom')
}
console.log(`scrollTop: ${scrollTop}`)
console.log(`windowHeight: ${windowHeight}`)
console.log(`scrollHeight: ${scrollHeight}`)
})
想要移动底部触发事件,是我哪里写的不对吗,一直不能正确获取
解决方案
问题可能是没加DOCTYPE,在此的情况下,$(document).height()=$(window).height()。
$(document).height()表示在网页实际内容高度没有满一屏时表示整个窗口的高度(窗口放大缩小时这个值会变化),页当超过一屏时表示为整个网页内容的实际高度。
$(window).height()在设DOCTYPE时无论网页内容实际高度超不超出满屏情况下,都等于是整个窗口的高度,如果没有设DOCTYPE则$(window).height()=$(document).height()。
这篇关于javascript - js控制移动到底部触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文