如何在滚动时从淡入淡出元素

How to fadeIn to fadeOut elements while scrolling?

本文关键字:淡入 淡出 元素 滚动      更新时间:2023-09-26

我的页面上有70多个div。

在用户滚动页面之前,我不想同时显示所有div。我试图在我的页面上隐藏溢出的元素,当用户滚动页面时,隐藏的div应该会再次消失。

但我无法隐藏溢出的元素,也找不到任何方法来隐藏溢出元素,若窗口滚动的话。

然而,我尝试了一下——

$(function(){
   $(window).css("overflow","hidden");
    var lengthy= $('.content').length;
         alert(lengthy);  
        var scrollbottom= $(window).scrollTop()+$(window).height();
        $(window).scroll(function(){
             $(document).css("overflow","hidden");
            if($(window).height() >scrollbottom)
            {
                $(document).fadeIn();
            }
        });

});

Jsfidle

如何做到这一点?

将Jquery编辑为类似的内容

$(window).scroll(function () { 
   if ($(window).scrollTop() >= $(document).height() - $(window).height() - 10) {
      //Add something at the end of the page
   }
});

这样做的目的是当滚动在页面结束前达到10px时发生,而不一定是在页面结束时。没有必要拥有它,但它提供了更大的控制权来定义页面应该滚动的点。。。

这个例子会告诉你我认为你想要什么http://www.webresourcesdepot.com/dnspinger/