Вызовите две пользовательских функции Jquery один за другим без участия Ajax

0

Я пытаюсь вызвать две пользовательские функции, так что функция B должна выполняться только после того, как функция A завершила задание. Обе функции не имеют функции ajax.

Я пытался, когда обещал, что никто из них, похоже, не работает для меня. Вот фрагмент двух функций.

   $.fn.closed = function() {
        alert("animation Finised!");
        $("#home-flipper").show("slide");
        $("#home").css("background-color", "#FBFE7B");
    };

    $.fn.start = function() {
        $("#home").css("background-color", "#212121");
        $("#os-phrases > h2").lettering('words').children("span").lettering().children("span").lettering();
    };

Подписной плагин

/*global jQuery */
/*! 
 * Lettering.JS 0.6.1
 *
 * Copyright 2010, Dave Rupert http://daverupert.com
 * Released under the WTFPL license 
 * http://sam.zoy.org/wtfpl/
 *
 * Thanks to Paul Irish - http://paulirish.com - for the feedback.
 *
 * Date: Mon Sep 20 17:14:00 2010 -0600
 */
(function($) {
    function injector(t, splitter, klass, after) {
        var a = t.text().split(splitter), inject = '';
        if (a.length) {
            $(a).each(function(i, item) {
                inject += '<span class="' + klass + (i + 1) + ' show_me">' + item + '</span>' + after;
            });
            t.empty().append(inject);
        }
    }

    var methods = {
        init: function() {

            return this.each(function() {
                injector($(this), '', 'char', '');
            });

        },
        words: function() {

            return this.each(function() {
                injector($(this), ' ', 'word', ' ');
            });

        },
        lines: function() {

            return this.each(function() {
                var r = "eefec303079ad17405c889e092e105b0";
                // Because it hard to split a <br/> tag consistently across browsers,
                // (*ahem* IE *ahem*), we replaces all <br/> instances with an md5 hash 
                // (of the word "split").  If you're trying to use this plugin on that 
                // md5 hash string, it will fail because you're being ridiculous.
                injector($(this).children("br").replaceWith(r).end(), r, 'line', '');
            });

        }
    };

    $.fn.lettering = function(method) {
        // Method calling logic
        if (method && methods[method]) {
            return methods[ method ].apply(this, [].slice.call(arguments, 1));
        } else if (method === 'letters' || !method) {
            return methods.init.apply(this, [].slice.call(arguments, 0)); // always pass an array
        }
        $.error('Method ' + method + ' does not exist on jQuery.lettering');
        return "done";
    };


})(jQuery);

Я попробовал следующее

$.when($(this).start()).then($(this).closed());

Но это не ответ на проблему, с которой я столкнулся. Пожалуйста, помогите мне решить эту проблему.

  • 0
    один из способов - заставить первую функцию возвращать значение по завершении, а затем проверить возвращаемое значение и выполнить вторую функцию
  • 0
    return команду с анимацией, это объект обещания, и это то, что, when ожидает
Показать ещё 5 комментариев
Теги:
callback
function

1 ответ

0

Наконец, я получил его на работу. Я не буду называть это идеальным решением, но мне нужно использовать эту настройку, пока кто-то не предложит мне что-то лучше.

Я просто использовал тайм-аут 20 секунд после вызова первой функции.

  $(this).start();
    $.doTimeout('closed', 20000, function() {
        $(this).closed();
    });

Ещё вопросы

Сообщество Overcoder
Наверх
Меню