$(window).scroll(function () { var scrollTop = $(this).scrollTop(); var documentHeight = $(document).height(); var windowHeight = $(this).height(); if (scrollTop + windowHeight == documentHeight) { } });滚动条到底部的条件即为scrollTop + windowHeight == documentHeight。(兼容不同的浏览器)。
如果文档高度小于window高度,则文档高度=window高度。
example:$(window).scroll(function () { var scrollTop = $(this).scrollTop(); var scrollHeight = $(document).height(); var windowHeight = $(this).height(); console.log('scrollTop:'+scrollTop); console.log('$(document).height():'+scrollHeight); console.log('windowHeight:'+windowHeight); if (scrollTop + windowHeight == scrollHeight) { alert('到底了!'); } });
滚动到底部判断条件
最新推荐文章于 2022-01-20 10:23:25 发布