调整动画以使div更频繁地出现

时间:2013-02-04 09:13:37

标签: javascript jquery

我正在制作一种打鼹鼠式的游戏,用户必须根据每次回答问题时随机生成的总和点击正确的数字。我遇到的问题是,用户有时需要等待很长时间才能显示出他们需要的答案,有时需要大约十秒才能显示出来。我需要动画来让div更频繁地出现,但我不知道如何实现这一点。

这是数字div的动画属性

function randomFromTo(from, to) {
    return Math.floor(Math.random() * (to - from + 1) + from);
}

function scramble() {
    var children = $('#container').children();
    var randomId = randomFromTo(1, children.length);
    moveRandom("char" + randomId);
}

var currentMoving = [];

function moveRandom(id) {
    // If this one's already animating, skip it
    if ($.inArray(id, currentMoving) !== -1) {
        return;
    }

    // Mark this one as animating
    currentMoving.push(id);

    var cPos = $('#container').offset();
    var cHeight = $('#container').height();
    var cWidth = $('#container').width();
    var bWidth = $('#' + id).width();

    var bHeight = $('#' + id).css('top', '395px').fadeIn(100).animate({
        'top': '-55px'
    }, AnimationSpeed).fadeOut(100);

    maxWidth = cPos.left + cWidth - bWidth;
    minWidth = cPos.left;
    newWidth = randomFromTo(minWidth, maxWidth);

    $('#' + id).css({
        left: newWidth
    }).fadeIn(1000, function () {
        setTimeout(function () {
            $('#' + id).fadeOut(1000);

            // Mark this as no longer animating                
            var ix = $.inArray(id, currentMoving);
            if (ix !== -1) {
                currentMoving.splice(ix, 1);
            }
            window.cont++;
        }, 1000);
    });
}

有人可以告诉我如何制作它,以便屏幕上一直有一定数量的答案,而不是现在的数字等待时间很长吗?

小提琴:http://jsfiddle.net/xgDZ4/3/

0 个答案:

没有答案