jquery - 使用CSS在向下滚动时淡入元素

标签 jquery css

示例: http://www.chartjs.org/

当向下滚动时,每篇文章都会在进入浏览器视口(viewport)时显示出来。 CSS是

#examples article {
    -webkit-transition: opacity 200ms ease-in-out;
    -ms-transition: opacity 200ms ease-in-out;
    -moz-transition: opacity 200ms ease-in-out;
    -o-transition: opacity 200ms ease-in-out;
    transition: opacity 200ms ease-in-out;
    position: relative;
    margin-top: 20px;
    clear: both;
}

我试过这个 css 但它不起作用。是否有一些与 css 一起工作的 javascript?如何实现这种滚动->淡入效果?

最佳答案

Demo Fiddle

你想要这样的东西吗?

   $(window).scroll(function () {

        /* Check the location of each desired element */
        $('.article').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);

            }

        });

    });

关于jquery - 使用CSS在向下滚动时淡入元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15590236/

相关文章:

javascript - 用于逐渐向下滚动的滚动按钮

html - 如何在 css 中的图像顶部创建网格线?

html - 为什么 flex 元素不缩小过去的内容大小?

html - 类输入组在 Firefox 和 IE 中不显示占位符或接受输入

css - 在悬停时显示 DIV - 自动溢出

javascript - mootools中使用Ajax加载文件

javascript - 切换jquery后如何留在div上?

javascript - 如何根据url参数返回部分页面

HTML,CSS。给定的字体大小占用了多少垂直像素?

javascript - 只希望我的功能在不再是移动设备时在更大的屏幕上进行