【问题标题】:Run 2 animations at once一次运行 2 个动画
【发布时间】:2013-01-03 10:13:35
【问题描述】:

我正在为儿童创建一个射击游戏,数字从下到上,他们必须点击与问题匹配的正确的数字。

我目前使用此代码开始从下到上移动数字

var bWidth = $('#' + id).width();
var bHeight = $('#' + id).css('top', '400px').fadeIn(1000).animate({
    'top': '-100px'
}, 7000).fadeOut(1000);

问题是当用户得到正确答案时,我会使用另一个动画来显示它是正确的,错误答案也是如此。

$(".character").click(function () {
    $(this).stop();
    if ($(this).hasClass("clock")) {
        if ($(this).hasClass("up")) {
            $(this).effect("explode", 300);
            count += 5;
        } else if ($(this).hasClass("down")) {
            $(this).effect("bounce", {
                times: 2,
                direction: 'left'
            }, 300, function() {
                $(this).slideUp('fast');
            });
            count -= 5;
        }
        $('#timer').text(count);
    } else {
        if ($(this).hasClass("wrong")) {
            $(this).effect("bounce", {
                times: 2,
                direction: 'left'
            }, 300, function() {
                $(this).slideUp('fast');
            });
            miss++;
            attempted++;
            $("#miss").html("Wrong: " + miss);
        } else {
            $(this).effect("explode", 300);
            hit++;
            attempted++;
            $("#hit").html("Right: " + hit);
            correctlabels();
        }
    }
});

我的问题是,当我点击数字时,在第二个动画开始之前会有很大的停顿,有时甚至根本不起作用。

我想知道是否有人可以告诉我解决此问题的方法,以便它顺利运行。谢谢!

这里有一个帮助:http://jsfiddle.net/pUwKb/19/

【问题讨论】:

    标签: javascript jquery animation jquery-animate


    【解决方案1】:

    在你的 animate() 选项中使用queue: false

    http://api.jquery.com/animate/

    【讨论】:

    • 当它被点击或移动时? @luuksen
    猜你喜欢
    • 2021-04-01
    • 2013-02-12
    • 2014-12-17
    • 2018-06-02
    • 2019-07-28
    • 2016-05-28
    • 1970-01-01
    • 1970-01-01
    • 2021-09-01
    相关资源
    最近更新 更多