需要帮助:动画 - 按钮点击 - >返回,一次

时间:2014-02-09 17:58:17

标签: javascript jquery animation

function animatethis(targetElement, speed) {
$(targetElement).animate({
    marginLeft: "+=250px"
}, {
    duration: speed,
    complete: function () {
        targetElement.animate({
            marginLeft: "-=250px"
        }, {
            duration: speed,
            complete: function () {
                animatethis(targetElement, speed);
            }
        });
    }
});
};

animatethis($('#q1'), 1000);

我需要一个按钮,按下它,循环将进行一次。就像攻击动画一样,按下按钮,图像会攻击其他图像。

1 个答案:

答案 0 :(得分:0)

在这里,你去找人......如果你有任何问题,请告诉我!

Working Example

// Animation Function
function animatethis(targetElement, speed) {    
    $(targetElement).animate({"margin-left" : "+=50px"}, speed, function(speed){
        $(this).animate({"margin-left" : "-=50px"}, speed);
    }); 
};

//Animation Trigger
$('body').on('click', 'button', function(){
    animatethis('#q1', 250);
});