0
How can I add Left, Right, Left diagonal, pause buttons in this code?
5 Answers
+ 1
You can assign Right function to Right Button
function Right() { var elem = document.getElementById ("myAnimation"); var pos = 0; var id = setInterval(frame, 10); function frame() { if (pos == 300) { clearInterval(id); } else { pos++; elem.style.left = pos + 'px'; } } }
but anyway you must to get current position always and not begin from 0. Of course, you must to check other conditions.
+ 1
Thank you
+ 1
and of course try to put in order all of your code using indentation and separating JS and CSS.
0
You only copy/paste my code but you must to do changes about which I said to work correctly.
0
function Down()
{
var elem = document.getElementById ("myAnimation");
var pos = 0;
var id = setInterval(frame, 10);
function frame()
{
if (pos == 300)
{
clearInterval(id);
}
else
{
pos++;
elem.style.top = pos + 'px';
}
}
}