probably just a little problem for someone who knows what he's doing...
I'd like to create something like this: https: //marvelapp.com/404 The Gif is loaded as fullscreen background und when you push "space" you get another gif and so on. After all the gifs are seen, the loop begins again.
So I searched how to do this and I found this approach (option 3): https: //www.linkedin.com/pulse/20140702040804-99746459-change-css-background-image-with-click (also used here: How to change css background-image on click? ) There it doesn't work with space but with mouse-click what is even better.
I tried to insert a while loop to get it working with more than two pics but... it doesn't work and I don't know why
My approach: http://jsfiddle.net/h3mfk347/
function updateIndex(){
while (index < 4) {
index++;
}
} index = 0;
bodyObj.onclick = function(e){
e.currentTarget.className = className[index];
updateIndex();
}
So I guess it's more a question of the loop than of the other parts.
Thanks for any help or hint :)
var index = 0; while ...forloop would probably be a better approach overall here.whileloop the way you're supposed to. Everything in the while loop happens at once, until the condition at the top of the loop is true. This makes your while loop doing the same thing as just setting the index to4.