简体   繁体   English

滚动事件上的淡入/淡出元素

[英]fading in/out elements on scroll event

I am trying to create a single vertical scroll landing page. 我正在尝试创建一个垂直滚动着陆页。 My HTML is structured with div's labeled as follows #slide-1, #slide-2 etc. all the way to #slide-5. 我的HTML的div结构如下:#slide-1,#slide-2等,一直到#slide-5。 Through the help of a quick plug-in and some variations I've made, I'm able to scroll the page with the elements fading in and fading out when you scroll past it. 通过快速插件和我所做的一些更改,我可以滚动页面,并在滚动时将元素淡入和淡出。 I'm just wondering if there is a way that when certain containers are in view, they have a specific animation done to them. 我只是想知道是否有办法在查看某些容器时对它们执行特定的动画处理。

Here is the js. 这是js。

    // Fading in the elements, etc. 
slides = $('.slide');
slides.children('.section').addClass('hiding');
$('#slide-1').children('.section').addClass('showing');
$('#slide-1').find('.centeredPromoImage').addClass('fadeInUpBig');
$(window).scroll(function(d,h) {
    slides.each(function(i) {
        a = $(this).position().top + $(this).height();
        b = $(window).scrollTop() + $(window).height();
        if (a < b) { 
            $(this).children('.section').removeClass('hiding').addClass('showing');
            $(this).find('.polaroid').addClass('fadeInRightBig');
            $(this).find('.left').addClass('fadeIn')
            $(this).siblings('.slide').children('.section').removeClass('showing').addClass('hiding');
        }
        var grabID = $(this).attr('id');
        console.log(grabID);
    });
});

I'm using animate.css for simple css3 animations on the page. 我将animate.css用于页面上的简单css3动画。 I had some issues using scrolldeck.js and am looking to create this with this or some variation of this code above. 我在使用scrolldeck.js时遇到了一些问题,并希望通过上面的代码或此代码的一些变体来创建它。

Also, if someone wouldn't mind clarifying why when I log grabID it returns all five slides, rather than the individual slide. 另外,如果有人不介意澄清为什么我登录grabID时会返回所有五张幻灯片,而不是单个幻灯片。

Thanks for your help! 谢谢你的帮助!

我之前使用waypoints.js滚动分析http://imakewebthings.com/jquery-waypoints/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM