当 body 窗口的顶部大于或等于 h2 标记时,将 h2 淡出,如果窗口的顶部回到该 h2 之上,则将该 h2 淡入。
当您向下滚动传递它时,此代码将淡出每个单独的 h2,但是当我向上滚动时,它不会淡出它,而且我不确定我做错了什么。我不是最擅长 jquery 的。非常感谢任何帮助。
$(window).scroll(function() {
$('.grid_12').find('h2').each(function () {
if ($(this).offset().top <= $('body').scrollTop()) {
$(this).fadeOut(500)
} else if
($(this).offset().top >= $('body').scrollTop()) {
$(this).prev().fadeIn(500)
}
});
});