only start moving the background once the page has fully loaded

This commit is contained in:
Ell 2022-02-02 22:17:39 +01:00
parent 0defd1da5a
commit f5c675ace4

View file

@ -35,13 +35,16 @@
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);
$(window).on("load", function () {
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);
});
</script>