相关疑难解决方法(0)

在向下滚动时淡入,在向上滚动时淡出 - 基于窗口中的元素位置

当它们在窗口中完全可见时,我试图让一系列元素在向下滚动时淡入.如果我继续向下滚动,我不希望它们淡出,但如果我向上滚动,我确实希望它们淡出.

这是我发现的最接近的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)

非常感谢您花时间看这个.

javascript jquery scroll fade

13
推荐指数
2
解决办法
8万
查看次数

标签 统计

fade ×1

javascript ×1

jquery ×1

scroll ×1