+ 4

Code in javascript Move circle by wheel.

hello, I have this code what I want is that when it reaches the end of the line it behaves like a wheel. The other thing is that when you go down to the second line and reach the limit of the if, when I want you to return in the opposite direction, you do it vehemently (quickly) I want it to be subtracting pixel by pixel. If anyone can give an opinion <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Index</title> <script> window.onload = function() { var pos = 0; var pos2=0; var pos3=0; //our box element var box = document.getElementById('mu'); var t = setInterval(move, 30); function move(){ if(pos>=1160){ pos2+=1; box.style.top= pos2+'px'; } else{ pos += 10; box.style.left= pos +'px'; } if(pos2>=110){ pos3-=1; box.style.left= pos3+'px'; } } }; </script>

11th Aug 2019, 3:50 PM
Edwin Boada
Edwin Boada - avatar
1 Answer
+ 1
instead of html element try to use canvas.. and use p5 js.. that will work but as of this problem i think you need to use position: absolute in that div..i m not sure about this. but as much code you post this is all i can do..
21st Apr 2020, 7:15 AM
Ayan Poddar
Ayan Poddar - avatar