淡入元素使用css向下滚动 [英] Fade in element on scroll down using css

查看:101
本文介绍了淡入元素使用css向下滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Example: http://www.chartjs.org/

当向下滚动每个文章时,它出现在浏览器的视口中。 css是

When scrolling down each article shows up when it gets in the view-port of the browser. The css is

#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,但它不工作。有一些javascript与css一起工作吗?如何实现这种scroll-> fadeIn效果?

I tried this css but it does not work. Is there some javascript that works together with the css? How can I achieve this kind of scroll->fadeIn effect?

推荐答案

小提琴

你想要这样的东西吗? / p>

Do you want something like this ?

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

            }

        });

    });

这篇关于淡入元素使用css向下滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆