Code:
var pictures = ["url(bildes/unity.png)", "url(bildes/xna.png)", "url(bildes/bge.png)"];
var countthearray = pictures.length;
var i = 0;
function MoveOneUp(){
i++;
document.getElementById("slaideris").style.backgroundImage=pictures[i];
if (i == countthearray-1) {
i =-1;
}
}
function MoveOneDown(){
--i;
document.getElementById("slaideris").style.backgroundImage=pictures[i];
if (i<0){
i=countthearray;
}
}
I'm trying to change the backgroundImage of a element via buttons, which have JS attached. If I use function MoveOneUp() everything works alright, but function MoveOneDown() seems to have some kind of problem that I don't understand.
Whenever I reach the last item of array, I have to click 2 times and only then it returns the array length value. Can someone explain me please where is the problem and how can I fix it?