Skip to content

Commit

Permalink
Update index.html
Browse files Browse the repository at this point in the history
  • Loading branch information
AJYaBoi authored Aug 5, 2024
1 parent 56183b0 commit c610dec
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@
justify-content: center;
align-items: center;
height: 100vh;
width: 100vw;
}
.dvd {
position: absolute;
width: 300px; /* Increased size */
height: 100px; /* Increased size */
width: 400px; /* Set size */
height: 200px; /* Set size */
background-size: contain;
background-repeat: no-repeat;
}
Expand All @@ -39,8 +40,8 @@
dvd.style.backgroundImage = `url(${dvdImages[currentImageIndex]})`;

// Initial position in the middle somewhere, not at the edge
let x = window.innerWidth / 4 + Math.random() * (window.innerWidth / 2 - dvd.clientWidth);
let y = window.innerHeight / 4 + Math.random() * (window.innerHeight / 2 - dvd.clientHeight);
let x = Math.random() * (window.innerWidth - dvd.clientWidth);
let y = Math.random() * (window.innerHeight - dvd.clientHeight);
let dx = 2;
let dy = 2;

Expand All @@ -50,12 +51,25 @@
}

function animate() {
if (x + dvd.clientWidth >= window.innerWidth || x <= 0) {
// Boundary checks
if (x + dvd.clientWidth > window.innerWidth) {
dx = -dx;
x = window.innerWidth - dvd.clientWidth; // Adjust position
changeImage();
}
if (y + dvd.clientHeight >= window.innerHeight || y <= 0) {
if (x < 0) {
dx = -dx;
x = 0; // Adjust position
changeImage();
}
if (y + dvd.clientHeight > window.innerHeight) {
dy = -dy;
y = window.innerHeight - dvd.clientHeight; // Adjust position
changeImage();
}
if (y < 0) {
dy = -dy;
y = 0; // Adjust position
changeImage();
}
x += dx;
Expand Down

0 comments on commit c610dec

Please sign in to comment.