使用jquery animate()实现对文本的反弹效果?

use*_*482 1 javascript jquery

我正在尝试使用Jquery来创建一个弹跳效果,这是我到目前为止所拥有的:

HTML:

<div id ="animation">bounce</div>
Run Code Online (Sandbox Code Playgroud)

jQuery的:

$("#animation").animate({ marginTop: "80px" }, 1500 )
               .animate({ marginBottom: "40px" }, 800 );
Run Code Online (Sandbox Code Playgroud)

它向下但不向上,我尝试搜索文档,但事实并非如此

这里的工作示例:http://jsfiddle.net/zLw8F/

Ber*_*rgi 6

要再次向上,你需要减少margin-top而不是动画margin-bottom:

$("#animation").animate({ marginTop: "80px" }, 1500 )
               .animate({ marginTop: "40px" }, 800 );
Run Code Online (Sandbox Code Playgroud)

在jsfiddle.net上演示

然而,为了使与页面其余部分分离的元素动画,我建议相对定位而不是使用边距.


j08*_*691 5

为什么不直接使用jQuery UI 效果?前任:

$("#animation").effect("bounce", { times:3 }, 300);?
Run Code Online (Sandbox Code Playgroud)

jsFiddle 示例