0

In my previous post i asked about making banner, after some searching i grasp some more concepts...

function animate(el)
{
var div = $(el);
return     div.css("display","block").animate({width:0},1).animate({width:1100},2000).delay(4000).hide(1);
}

$(document).ready(function(){
    var dfd = $.Deferred(), 
    chain = dfd;

 var slide = ['#img2'];

$.map(slide, function(el) {
    chain = chain.pipe(function() {
        return animate(el).promise();
    });
}); 

return dfd.resolve();                
});

Here is my code, i am wondering to make it continous, when the slide array finish it doesnt display any more pictures. I want to repeat the whole sequence.

Wajahat Kareem
  • 325
  • 2
  • 4
  • 14
  • possible duplicate of [Jquery Continuously Loop Animation](http://stackoverflow.com/questions/6767286/jquery-continuously-loop-animation) – Andrew Cheong Jan 13 '13 at 09:33
  • 1
    Make it a recursive function, at the end of the current function put a setTimeout(function(){animate(el);}, XXX); so that it repeats itself every XXX milliseconds – aurbano Jan 13 '13 at 09:36
  • I tried both of your suggestions but it doesnt work , or i have placed the functions at wrong points, can u guide me where to place this function. – Wajahat Kareem Jan 13 '13 at 10:14

1 Answers1

0

Extending on the recursive function comment from Chevi.

function recursiveFunction() {

    // execute the function's code (i.e. your banner animation)

    // recurse after 1 second
    setTimeout(recursiveFunction, 1000);
}

This is an example of using recursion with a timer.
You will of course have to modify it to suit your code.

diggersworld
  • 12,770
  • 24
  • 84
  • 119
  • I can do animation for one banner , but in above code i am changing pictures so i have to recall the call back function in the last. I have problem in multiple pictures, one picture changing is easy for me. – Wajahat Kareem Jan 13 '13 at 12:12