我有一个元素总是保持在屏幕底部的5%(位置:固定;底部:5%;)。
这只是一个暗示,即“向下滚动”。当你到达屏幕的底部时,我想让它渐渐消失。
如何检测用户是否已到达屏幕底部?
答案 0 :(得分:2)
您需要获取文档的宽度并使用窗口宽度和滚动偏移计算它:
if (documentWidth == (windowWidth + scrollOffset)) {
$('#hint').fadeOut();
}
答案 1 :(得分:1)
使用jquery scroll()方法:
var fadeFlag = false;
$(window).scroll(function(e) {
// Check if we reached bottom of the document and fadeOut the target element
if( $(window).height() + $("html").scrollTop() == $(document).height()-1) {
$('#target').fadeOut();
fadeFlag = true;
} else {
// Here you can do fadeIn
if(fadeFlag) $('#target').fadeIn();
fadeFlag = false;
}
});
我使用 $(“html”)而不是 $(窗口),因为它不会让你在IE8中遇到麻烦