0

希望您能帮助解决 jQuery 中的动画问题。我正在使用以下代码制作一个可以启动和停止的动画循环,并且可以选择动画元素是脉冲还是移动,如箭头所示:

//set the flashing pointer on or off
function flashPointer(state, time, el, style){
    switch(state){
        case "on":
            loopPointer(time, style, el);
        break;
        case "off":
            $(el).stop(true, false).fadeOut(100, function(){ 
                $(el).clearQueue();
            });
        break;
    }   

}

//make a pointer graphic fade in and out
function loopPointer(time, style, el){
    switch(style){
        case "fade":
        $(el).fadeIn(time, function(){
            $(this).fadeOut(time, function(){
                loopPointer(1000, "fade", el);
            }); 
        });
        break;

        case "move":
        $(el).fadeIn(time).animate({top:15}, time, function(){
            $(this).animate({top:0}, function(){
                loopPointer(1000, "move", el);
            }); 
        });
    }
}

知道为什么如果我多次启动和停止动画,它会变得越来越慢吗?

当然也欢迎任何其他意见和改进点。

谢谢大家 ;)

杰米

更新

我这样调用这些函数:

flashPointer("on", 1000, "#pointer", "move");
flashPointer("off", 1000, "#pointer", "move");
flashPointer("on", 1000, "#pointer", "fade");
flashPointer("off", 1000, "#pointer", "fade");

我调用一次上述函数来打开推子,例如,当浏览器请求访问用户的地理位置信息时,一旦获得所需的信息/权限,再次调用以将其关闭。

希望这有助于解释我想要做什么?

谢谢你的帮助!

杰米

4

0 回答 0