当它们在窗口中完全可见时,我试图让一系列元素在向下滚动时淡入.如果我继续向下滚动,我不希望它们淡出,但如果我向上滚动,我确实希望它们淡出.
这是我发现的最接近的jsfiddle. http://jsfiddle.net/tcloninger/e5qaD/
$(document).ready(function() {
/* Every time the window is scrolled ... */
$(window).scroll( function(){
/* Check the location of each desired element */
$('.hideme').each( function(i){
var bottom_of_object = $(this).position().top + $(this).outerHeight();
var bottom_of_window = $(window).scrollTop() + $(window).height();
/* If the object is completely visible in the window, fade it it */
if( bottom_of_window > bottom_of_object ){
$(this).animate({'opacity':'1'},500);
}
});
});
});
Run Code Online (Sandbox Code Playgroud)
它完全按照我想要的向下滚动,但如果我向上滚动它们,我也希望元素淡出.
我试了这个没有运气.
if( bottom_of_window > bottom_of_object ){
$(this).animate({'opacity':'1'},500);
} else {
$(this).animate({'opacity':'0'},500); }
Run Code Online (Sandbox Code Playgroud)
非常感谢您花时间看这个.