mirror of
https://github.com/Ellpeck/TinyLifeWeb.git
synced 2024-11-26 04:48:34 +01:00
18 lines
466 B
JavaScript
18 lines
466 B
JavaScript
|
let x = Math.random() * 100;
|
||
|
let y = Math.random() * 100;
|
||
|
|
||
|
let angle = Math.random() * 2 * Math.PI;
|
||
|
let addX = Math.cos(angle) * 0.02;
|
||
|
let addY = Math.sin(angle) * 0.02;
|
||
|
|
||
|
let background = $(".top");
|
||
|
background.css("background-position", `${x}% ${y}%`);
|
||
|
setInterval(function () {
|
||
|
x += addX;
|
||
|
y += addY;
|
||
|
if (x < 0 || x > 100)
|
||
|
addX *= -1;
|
||
|
if (y < 0 || y > 100)
|
||
|
addY *= -1;
|
||
|
background.css("background-position", `${x}% ${y}%`);
|
||
|
}, 30);
|