+ 1
please help
why syntax error? https://code.sololearn.com/Wf9YP1l6u4jY/?ref=app
10 Respostas
+ 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;
}
+ 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
+ 3
Арсений you forget to give parentheses setInterval(function{
^
It should be
setInterval(function () {
+ 3
thank you)))
+ 2
SoloProg thanks))
but a hint:you can do onclick="angle+=45"
JavaScript in the oncklick
+ 2
I made a game)))
+ 2
will made
+ 1
please please please please heeelp
+ 1
thanks
+ 1
how to change x, y of my div? style.top and left is not work(((