Soldato
- Joined
- 12 May 2007
- Posts
- 3,896
- Location
- Bristol
I've come across this little jquery function which simply rotates through divs and sets them to show. However, I need it to repeat back to the first div once it reaches the end but have no clue how to do so. Can anyone point me in the right direction.
Edit: I got it working. However, is there a better way to do it?
Code:
$.fn.cycle = function(timeout){
var $all_elem = $(this)
show_cycle_elem = function(index){
if(index == $all_elem.length) return;
$all_elem.hide().eq(index).fadeIn()
setTimeout(function(){show_cycle_elem(++index)}, timeout);
}
show_cycle_elem(0);
}
$(document).ready(function() {
$("#signs a").cycle(1000)
});
Edit: I got it working. However, is there a better way to do it?
Code:
$.fn.cycle = function(timeout){
var $all_elem = $(this)
show_cycle_elem = function(index){
if(index == $all_elem.length) return show_cycle_elem(0);
$all_elem.hide().eq(index).fadeIn()
setTimeout(function(){show_cycle_elem(++index)}, timeout);
}
show_cycle_elem(0);
}
Last edited: