I stumbled upon an interesting example where a loop is created involving 4 div's http://jsfiddle.net/w5YHY/2/
var $elements = $('#One, #Two, #Three, #Four');
$elements.eq(i).fadeIn(1000, function() {
var $self = $(this);
setTimeout(function() {
$self.fadeOut(1000);
anim_loop((i + 1));
}, 3000);
});
The loop works fine.
I had the following queries in my mind.
Each radio button corresponds to a div. If the loop is at position 3, radio 3 should be selected and so on. How is this done? Vice-versa the radio should manipulate the loop, something like a 2-way binding.
Moreover clicking the left and right buttons should also change the loop. So assume the loop is at position 3 and the left button is clicked, it should go back to 2.
How can I do all these event bindings elegantly without repeating code?