【问题标题】:How to make div fade in/out on scroll如何使div在滚动时淡入/淡出
【发布时间】:2013-06-12 11:49:32
【问题描述】:

需要一些建议:我正在寻找创建一个在页面滚动时响应地工作的淡入/淡出脚本。我想做什么:

  • 在滚动时,一旦到达隐藏的 div,就会淡入。
  • 一旦滚动到达页面顶部,它就会淡出。
  • 任何未来的卷轴都会让 div 淡入淡出,就像它出现/消失一样。

这是一个创建淡入淡出的示例代码,但只执行一次。我需要它在每次触发时淡入淡出。

    $(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);

        }

    }); 

    });

    });

有什么建议吗?

谢谢,我希望这是有道理的!

【问题讨论】:

  • 添加了我要评论的代码

标签: javascript jquery html responsive-design


【解决方案1】:

你考虑过 jQuery Waypoints 吗?它是一个插件,可让您在滚动到元素时执行功能。

http://imakewebthings.com/jquery-waypoints/

然后,您可以在滚动到该元素时对其执行 .fadeIn() 。

【讨论】:

  • 我见过 Waypoints,但我不是 100% 确定如何实现它。我的 jquery 技能很基础。
猜你喜欢
  • 2012-03-15
  • 1970-01-01
  • 2012-05-25
  • 1970-01-01
  • 2013-02-20
  • 1970-01-01
  • 1970-01-01
  • 2021-02-14
  • 2016-03-09
相关资源
最近更新 更多