I have the following code in which I try to give a movement animation to several buttons and that gives me an error:
//variables de la animación
var button0 = document.getElementById("button0");
var button1 = document.getElementById("button1");
var button2 = document.getElementById("button2");
var button3 = document.getElementById("button3");
var pos0 = 0;
var pos1 = 0;
var pos2 = 0;
var pos3 = 0;
var direction0 = "down";
var direction1 = "down";
var direction2 = "down";
var direction3 = "down";
//proceso
function animateButton(button, pos, direction) {
if (pos == 20) {
direction = "up";
} else if (pos == 0) {
direction = "down";
}
if (direction == "down") {
button.setAttribute("style", "top:" + pos + "px");
pos++;
} else if (direction == "up") {
button.setAttribute("style", "top:" + pos + "px");
pos--;
}
}
setInterval( function() { animateButton(button0, pos0, direction0); }, 90 );
setInterval( function() { animateButton(button1, pos1, direction1); }, 90 );
setInterval( function() { animateButton(button2, pos2, direction2); }, 90 );
setInterval( function() { animateButton(button3, pos3, direction3); }, 90 );
What can you owe?