+ 2

How to get random positions for the golden elements automatically?

https://code.sololearn.com/W81RrJSxbtga/?ref=app Using Math.floor((Math.random() * 250) + 1); ???

12th Aug 2018, 8:37 AM
B.D
B.D - avatar
8 odpowiedzi
+ 2
thank you very much
12th Aug 2018, 2:57 PM
B.D
B.D - avatar
+ 2
and how to get the current position of the virus?
12th Aug 2018, 3:18 PM
B.D
B.D - avatar
+ 1
// to update golden object position function setGoldenPos(x,y) { var virus = document.querySelector("#virus"); virus.style.left = x + "px"; virus.style.top = y + "px"; } // to get a random number from max value function getRandom(max) { return Math.floor(Math.random() * max); } // set random position x,y within the container setGoldenPos(getRandom(350-25),getRandom(350-35)); https://code.sololearn.com/W75Z1jn7GQY0/?ref=app
12th Aug 2018, 11:50 AM
Calviղ
Calviղ - avatar
+ 1
In motion?
12th Aug 2018, 11:51 AM
B.D
B.D - avatar
+ 1
How does the motion look like? From where to where? Control by what element?
12th Aug 2018, 11:54 AM
Calviղ
Calviղ - avatar
+ 1
random position sliding motion
12th Aug 2018, 11:54 AM
B.D
B.D - avatar
+ 1
Just add setInterval with transition css Check the code out again.
12th Aug 2018, 12:16 PM
Calviղ
Calviղ - avatar
+ 1
// position of virus in integer var virus = document.querySelector("#virus"); var posX = parseInt(virus.style.left, 10); var posY = parseInt(virus.style.top, 10);
12th Aug 2018, 4:36 PM
Calviղ
Calviղ - avatar