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
Try this:
html:
javascript:
The key is the global variable window.is_toggled, although you can use any name: window.my_variable, or whatever. You don’t need to initially declare it with “var” as, fortunately, !undefined = true.
Hope that helps? Good luck!