+ 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); ???
8 Réponses
+ 2
thank you very much
+ 2
and how to get the current position of the virus?
+ 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
+ 1
In motion?
+ 1
How does the motion look like? From where to where? Control by what element?
+ 1
random position
sliding motion
+ 1
Just add setInterval with transition css
Check the code out again.
+ 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);