【问题标题】:Animation | Wait until the first animation still run动画 |等到第一个动画还在运行
【发布时间】:2012-10-15 11:55:13
【问题描述】:

我尝试创建自己的幻灯片供个人使用,但遇到了问题。

在我的 jQuery 插件中,我创建了一个操作我的插件的对象。代码结构如下:

(
    function($)
    {
        $.fn.wplSlider = function(options)
        {
            var slider     =   this;

            var settings    =   $.extend(
                {
                    'animationSpeed'    :   750,
                    'animationEasing'   :   null,
                    'animationAutoStart':   true,
                    'pauseTime'         :   3500
                },
                options
            );

            var methods =   {
                animationRun        :   false,
                totalSlides         :   0,
                init                :   function()
                {
                    // This method initiating the slide show elements
                },
                slidesStatus        :   function()
                {
                    // This method initiating the slides status
                },
                slideNumber         :   function()
                {
                    // Assign a number to each slide
                },
                getSlidesAmount     :   function()
                {
                    // Get the amount of slides
                },
                next                :   function()
                {
                    // Prepare the next slide that will be displayed
                },
                prev                :   function()
                {
                    // Prepare the next slide that will be displayed
                },
                goTo                :   function(item)
                {
                    // Prepare the specified slide
                },
                slideOut            :   function()
                {
                    // Slide out the current slide
                    slider.find('li[data-status="current"] .container').animate(
                        {
                            top :   '-75px'
                        },
                        600
                    );

                    slider.find('li[data-status="current"] span, li[data-status="current"] a').animate(
                        {
                            opacity :   0
                        },
                        600
                    );
                },
                slideIn             :   function()
                {
                    // Slide in the current slide
                    $('li[data-status="current"]').animate(
                        {
                            'opacity'   :   1
                        },
                        650
                    );
                }
            }

            /* Allow chainability */
            return this.each(
                function()
                {
                    methods.init();
                    methods.slideOut();
                    methods.next();
                    methods.slideIn();
                }
            );
        }
    }
)(jQuery);

用上面的代码,问题是,当我执行slideOut/next/slideIn的时候,步骤非常快。

更具体地说,slideIn() 与 slideOut() 同时执行。

有没有办法让slideIn()只有在slideOut()完成后才执行?

【问题讨论】:

    标签: jquery animation jquery-animate


    【解决方案1】:

    有没有办法让 slideIn() 只在 slideOut() 完成了吗?

    是的,您可以使用以下代码。

    下面的代码将允许您运行 slideIn() 函数将在执行 slideOut() 函数时执行。

    $.when(methods.slideOut())
      .then(methods.slideIn());
    

    Read more

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-08
    • 2014-11-16
    • 1970-01-01
    • 2016-11-29
    • 2023-03-17
    相关资源
    最近更新 更多