本文介绍了jQuery 动画循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的动画循环有问题.有一个对象我想以一种特殊的方式移动并循环进行.是否有任何本机选项可以实现?我有这个:
I have a problem with animate loop. There is an object i want to move in a special way and do it in loop. Are there any native options to make it? I have this:
$(function () {
function runIt() {
$('#div').show("slow");
$('#div').animate({"marginLeft":"300px"},8000);
$('#div').animate({"marginLeft":"0px"},8000);
$('#div').hide("slow", runIt);
}
runIt();
});
不过好像没那么好看.
推荐答案
这就是我要做的.我唯一的建议是使用链接来编写更好的代码,这样就不会每次都创建 jquery 对象.
That is how I would do it. The only suggestion I would make is to use chaining for nicer code and so the jquery object doesn't get created every time.
$(function () {
function runIt() {
$('#div').show("slow")
.animate({"marginLeft":"300px"},8000)
.animate({"marginLeft":"0px"},8000)
.hide("slow", runIt);
}
runIt();
});
这篇关于jQuery 动画循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!