如何循环一个jQuery div动画? [英] how to loop a jquery div animation?

查看:71
本文介绍了如何循环一个jQuery div动画?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用无限循环实现jQuery函数以使div动画化.我不知道该怎么做.这是我的代码:

I’m trying to implement a jQuery function with an infinite loop to animate a div. I can’t figure out how to do it. This is my code:

$(document).ready(function() {
    $('#divers').animate({'margin-top':'90px'},6000).animate({'margin-top':'40px'},6000);
});

推荐答案

将完整动画的代码放入函数中,然后将该函数作为回调参数传递给最后一个动画.像...

put the code that does the full animation into a function, then pass that function as the callback param to the last animation. Something like...

$(document).ready(function() {   
    function animateDivers() {
        $('#divers').animate(
            {'margin-top':'90px'}
            ,6000
        )
        .animate(
            {'margin-top':'40px'}
            ,6000
            ,animateDivers //callback the function, to restart animation cycle
        ); 
    }

    animateDivers(); //call, to start the animation
}); 

这篇关于如何循环一个jQuery div动画?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆