简体   繁体   English

向上滚动时,Skrollr.js将启动另一个动画

[英]Skrollr.js start another animation when scroll up

I'm working with Skrollr.js. 我正在使用Skrollr.js。 And i have this animations when scroll from top to bottom: 从上到下滚动时,我有以下动画:

 <div
    class="flight-icon-d __d"
    data-anchor-target=".section.__flight"
    data-top-top="top: 126px; transform: translateX(-50%) rotate(-135deg) scale(0.35);"
    data--50-top="transform: translateX(-50%) rotate(0deg) scale(0.35);"
    data--150-top="top: 425px; transform: translateX(-50%) rotate(0deg) scale(1);"
    data--550-top="top: 745px; transform: translateX(-50%) rotate(0deg) scale(1);"
    data--780-top="top: 980px; transform: translateX(-50%) rotate(0deg) scale(0.35);"></div>

So when I scroll up my animation goes backwards. 因此,当我向上滚动时,动画将向后移动。 How can I change animation on scrolling up? 如何在向上滚动时更改动画?

you can use below js with animate.css. 您可以将以下js与animate.css一起使用。

JS JS

 /* Check Which Section Visible on screen*/
    $(document).ready(function() {
        var $animation_elements = $('.animate-box');
        var $window = $(window);    
        function check_if_in_view() {
            var window_height = $window.height();
            var window_top_position = $window.scrollTop();
            var window_bottom_position = (window_top_position + window_height);

            $.each($animation_elements, function() {
                var $element = $(this);
                var element_height = $element.outerHeight();
                var element_top_position = $element.offset().top;
                var element_bottom_position = (element_top_position + element_height);

                //check to see if this current container is within viewport
                if ((element_bottom_position > window_top_position) &&
                    (element_top_position < window_bottom_position)) {
                    $element.addClass('in-view');                
                    var cls = ".in-view .animated";
                    $(cls).each(function() {
                        var animationName = $(this).attr("animate");                    
                        if (animationName !== undefined) {
                            /* Chrome & Safari */
                            $(this).css('-webkit-animation-duration', $(this).attr("duration"));
                            /*Mozila*/
                            $(this).css('-moz-animation-duration', $(this).attr("duration"));
                            /*Opera*/
                            $(this).css('-o-animation-duration', $(this).attr("duration"));
                            /* Chrome & Safari */
                            $(this).css('-webkit-animation-delay', $(this).attr("delay"));
                            /*Mozila*/
                            $(this).css('-moz-animation-delay', $(this).attr("delay"));
                            /*Opera*/
                            $(this).css('-o-animation-delay', $(this).attr("delay"));
                            var animationEnd = 'webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend';
                            $(this).addClass(animationName).one(animationEnd, function() {
                                $(this).removeClass('animated ' + animationName)
                            });
                        }
                    });
                } else {
                    $element.removeClass('in-view');
                }
            });
        }
        $window.on('scroll resize', check_if_in_view);
        $window.trigger('scroll');
    });

HTML CODE: HTML代码:

<section id="section2" class="bg bg-2 animate-box">                 
                <div class="box animated" animate="fadeIn" duration="2s" delay="1s" > ... </div>
</section>

DEMO URL 演示网址

http://plugins.auratechmind.net/scrolltoanimate

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

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