【问题标题】:Animation repeats after the first animate is finished, how to cancel it?第一个动画完成后动画重复,如何取消?
【发布时间】:2017-04-13 17:23:51
【问题描述】:

我正在尝试创建一个设计,您单击一个框,它会滑入另一个包含更多内容的视图,当您单击箭头时,它会返回。

问题是这样的:

        $(boxes).one('webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend', function() {
            boxes.parent().css({ 
                'height' : '0', 
                'opacity' : '0',
                'overflow' : 'hidden'
            });

            fboxContentCover.css({
             'height' : 'auto',
             'opacity' : '1',
            });

            fboxContentCover.removeClass('fadeOutLeft').addClass('animated bounceInRight');
        });

        $(fboxContentCover).one('webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend', function() {

            fboxContentCover.css({ 
                'height' : '0', 
                'opacity' : '0',
                'overflow' : 'hidden'
            });

            $('.fbox').parent().css({
             'height' : 'auto',
             'opacity' : '1',
            });

            $('.fbox').removeClass('fadeOutLeft').addClass('animated fadeInRight');
        });

当第一个完成后,它成功进入第二个视图,但是当你点击返回时,它会再次滑入第一个视图,但它会再次闪烁第二个视图然后返回又是第一个视图。

我怎样才能阻止这种情况发生?

代码和一切都在这里:https://codepen.io/anon/pen/JNodjO

【问题讨论】:

    标签: jquery css animate.css


    【解决方案1】:

    您的 .removeClass 似乎无法正常工作 - 课程似乎正在重新附加。

    从使用.addClass.removeClass 切换到-> .toggleClass

    更适合像你这样的场景。更容易在类之间切换,因此得名

    【讨论】:

    • 你能编辑codepen并告诉我你的意思吗?我改成:fboxContentCover.toggleClass('fadeOutLeft animated bounceInRight');boxes.toggleClass('fadeOutLeft animated fadeInRight');第二个视图动画没有发生然后返回,动画停止。
    • @kinx 我不能为你做这一切!不过这个方法应该行得通,祝你好运!
    猜你喜欢
    • 1970-01-01
    • 2014-11-16
    • 2021-11-27
    • 1970-01-01
    • 1970-01-01
    • 2020-05-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多