24th Dec 2021, 6:56 PM
Арсений G-5
Арсений G-5 - avatar
10 Answers
+ 2
HTML <div id="gg" onclick="SetAngle()"></div> CSS div{ background-color: #000; height: 10px; width: 10px; position:relative ; cursor: pointer; } JS var hh=document.getElementById("gg"); var x=0; var y=0; var angle=0; window.onload=()=>{ setInterval(function(){ x+=Math.cos(angle)*10; y+=Math.sin(angle)*10; hh.style.left = x +"px"; hh.style.top = y +"px"; },1000); } SetAngle = () => { angle+=45; }
24th Dec 2021, 10:19 PM
SoloProg
SoloProg - avatar
+ 4
Арсений 1. Give element position as relative or absolute or ... 2. Give some units to your value (Here i have use pixels u can use your own value ) https://code.sololearn.com/WO1AviB41C02/?ref=app
24th Dec 2021, 7:16 PM
Pariket Thakur
Pariket Thakur - avatar
+ 3
Арсений you forget to give parentheses setInterval(function{ ^ It should be setInterval(function () {
24th Dec 2021, 7:06 PM
Pariket Thakur
Pariket Thakur - avatar
+ 3
thank you)))
24th Dec 2021, 7:19 PM
Арсений G-5
Арсений G-5 - avatar
+ 2
SoloProg thanks)) but a hint:you can do onclick="angle+=45" JavaScript in the oncklick
27th Dec 2021, 6:48 AM
Арсений G-5
Арсений G-5 - avatar
+ 2
I made a game)))
27th Dec 2021, 6:50 AM
Арсений G-5
Арсений G-5 - avatar
+ 2
will made
27th Dec 2021, 6:51 AM
Арсений G-5
Арсений G-5 - avatar
+ 1
please please please please heeelp
24th Dec 2021, 6:59 PM
Арсений G-5
Арсений G-5 - avatar
+ 1
thanks
24th Dec 2021, 7:10 PM
Арсений G-5
Арсений G-5 - avatar
+ 1
how to change x, y of my div? style.top and left is not work(((
24th Dec 2021, 7:13 PM
Арсений G-5
Арсений G-5 - avatar