diff options
| author | Peter Nguyen <peteralistairnguyen@gmail.com> | 2025-02-14 10:40:44 -0600 |
|---|---|---|
| committer | Peter Nguyen <peteralistairnguyen@gmail.com> | 2025-02-14 10:40:44 -0600 |
| commit | c15181ea2bdeb4b080762d08260d927ad1fff9f5 (patch) | |
| tree | 36a2c8b48b627a2309bce3f7f64000deb7d622d3 /scripts/valentine.js | |
| parent | 110dc2831488937c1afb70c11657a341912fc8cd (diff) | |
Valentine's Day 2025
Diffstat (limited to 'scripts/valentine.js')
| -rw-r--r-- | scripts/valentine.js | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/scripts/valentine.js b/scripts/valentine.js new file mode 100644 index 0000000..6347b87 --- /dev/null +++ b/scripts/valentine.js @@ -0,0 +1,37 @@ +const btn = document.getElementById("moveBtn"); + +btn.addEventListener("mouseover", () => { + let randX = (Math.random() * 600) - 300; // Move randomly left/right up to 200px + let randY = (Math.random() * 600) - 300; // Move randomly up/down up to 200px + + // Get viewport dimensions + const viewportWidth = window.innerWidth; + const viewportHeight = window.innerHeight; + + // Get button dimensions + const btnRect = btn.getBoundingClientRect(); + + // Ensure button stays within viewport + randX = Math.min(Math.max(randX, -btnRect.left), viewportWidth - btnRect.right); + randY = Math.min(Math.max(randY, -btnRect.top), viewportHeight - btnRect.bottom); + + btn.style.transform = `translate(${randX}px, ${randY}px)`; +}); + +btn.addEventListener("click", () => { + let randX = (Math.random() * 600) - 300; // Move randomly left/right up to 200px + let randY = (Math.random() * 600) - 300; // Move randomly up/down up to 200px + + // Get viewport dimensions + const viewportWidth = window.innerWidth; + const viewportHeight = window.innerHeight; + + // Get button dimensions + const btnRect = btn.getBoundingClientRect(); + + // Ensure button stays within viewport + randX = Math.min(Math.max(randX, -btnRect.left), viewportWidth - btnRect.right); + randY = Math.min(Math.max(randY, -btnRect.top), viewportHeight - btnRect.bottom); + + btn.style.transform = `translate(${randX}px, ${randY}px)`; +});
\ No newline at end of file |
