I need to run the code sample below so that it works on a toggle, so when the div is clicked it starts the image rotation and when it is clicked again it starts and so on? Thanks in advance :)
$('#pause_button1').click(function() {
/* need to run this when clicked - need a toggle */
function changeImage(element, imageNumber){
imageNumber++;
if(imageNumber > 6){
imageNumber = 1;
}
console.log(imageNumber);
element.addClass('pause_button' + imageNumber, 200);
element.attr('class', 'pause_button' + imageNumber);
setTimeout(function(){changeImage(element, imageNumber)}, 200);
}
changeImage($('#pause_button'), 0);
});
example: jsfiddle
if you look at this example: jsfiddle.net/AKgZn/2 it needs to cycle when the white square (#pause_button1) is clicked and when its cycling and you click the cycling square again it returns to the white square