Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
158
rated 0 times [  165] [ 7]  / answers: 1 / hits: 25709  / 13 Years ago, tue, june 14, 2011, 12:00:00

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();
});


But it seems not so pretty.


More From » jquery

 Answers
78

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();
});

[#91720] Monday, June 13, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
raymondd

Total Points: 620
Total Questions: 112
Total Answers: 94

Location: Namibia
Member since Mon, Feb 21, 2022
2 Years ago
raymondd questions
Thu, Apr 22, 21, 00:00, 3 Years ago
Thu, Jul 9, 20, 00:00, 4 Years ago
Thu, Apr 9, 20, 00:00, 4 Years ago
Thu, Jul 25, 19, 00:00, 5 Years ago
;