0

抱歉这个菜鸟问题,我正在尝试让三个红色的气泡一个一个出现,请在此处查看我的代码:http: //jsfiddle.net/FLt9Z/

该部分的 javascript 如下所示:

function leftappear() {
    $('#redbubble-left').show();
}

function topappear() {
    $('#redbubble-top').show();
}

function rightappear() {
    $('#redbubble-right').show();
}


var animation_script = [
    {
         at_time: 30 * 1000, // 30 seconds
         animation: leftappear()
    },
    {
         at_time: 31 * 1000, // 31 seconds
         animation: topappear()
    },
    {
         at_time: 32 * 1000, // 32 seconds
         animation: rightappear()
    }
];

var current_time = 0;

function animate_next() {
    var next = animation_script.shift(),
        time_between = next.at_time - current_time;
    setTimeout(function () {
        current_time = next.at_time;
        next.animation();
        animate_next();
    }, time_between);
}

非常感谢你们!

4

2 回答 2

4

两个问题:

  1. 你在调用动画方法而不是在你的动画脚本中引用它们
  2. 你永远不会触发下一个 FIRST 动画。

http://jsfiddle.net/FLt9Z/1/

这是两个主要变化。

var animation_script = [
    {
         at_time: 2* 1000, // 30 seconds
         animation: leftappear // NOTE: drop the parens ()
    },
    {
         at_time: 3* 1000, // 31 seconds
         animation: topappear // NOTE: drop the parens ()
    },
    {
         at_time: 4* 1000, // 32 seconds
         animation: rightappear // NOTE: drop the parens ()
    }
];

然后2,开始,我只是添加animate_next();到底部。您可以将它放在顶部或其他地方的初始化脚本中。这仅用于演示目的。

于 2012-11-14T22:14:58.820 回答
2

除了第一个答案之外,我还想指出您当前的代码会继续调用自身,即使它通过了要显示的气泡列表,而是我只会循环一次并设置超时:

$.each(animation_script, function(i, animation) {
    var next = animation_script.shift(),
        time_between = next.at_time - current_time;
    setTimeout(function() {
        current_time = next.at_time;
        next.animation();
    }, time_between);
});
于 2012-11-14T22:21:56.337 回答