我有一个代码在滚动到达底部之前得到300px时显示一些内容!当达到底部时,我想在离开底部后达到300px时摆脱此消息!在离开底部之后做一些300px的事
当我在底部之前达到300像素时,它完美地起作用,但当我尝试向后滚动300像素时它不起作用。
document.addEventListener('scroll', function(event) {
var docHeight = $(document).height(); // Document height
var winHeight = $(window).height(); // Window height
var minHeight = docHeight - winHeight; // Real document height
var curHeight = $(window).scrollTop(); // Display the height according to scrolling
$(window).scroll(function() {
//BEFORE
if(curHeight + 300 > minHeight) {
document.getElementById('copyrights').innerHTML = "Welcome to bottom";
}
//AFTER (doesn't work)
if(curHeight - 300 == minHeight - 300) {
document.getElementById('copyrights').innerHTML = "Good bye";
}
});
});
您没有说明哪部分代码不起作用。 – which1ispink
刚刚编辑,对不起! =/ –