How can I add Left, Right, Left diagonal, pause buttons in this code? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How can I add Left, Right, Left diagonal, pause buttons in this code?

https://code.sololearn.com/W81RrJSxbtga/?ref=app

20th Oct 2017, 11:21 AM
B.D
B.D - avatar
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.
9th Nov 2017, 1:04 AM
Daniel
Daniel - avatar
+ 1
Thank you
9th Nov 2017, 12:23 PM
B.D
B.D - avatar
+ 1
and of course try to put in order all of your code using indentation and separating JS and CSS.
9th Nov 2017, 1:47 PM
Daniel
Daniel - avatar
0
You only copy/paste my code but you must to do changes about which I said to work correctly.
9th Nov 2017, 1:45 PM
Daniel
Daniel - avatar
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'; } } }
9th Nov 2017, 1:50 PM
Daniel
Daniel - avatar