-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor font and video sources, add transition and transform to card
- Loading branch information
HiiZun
committed
Oct 21, 2024
1 parent
4cd3138
commit 96db16d
Showing
3 changed files
with
25 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,26 @@ | ||
document.addEventListener('DOMContentLoaded', function() { | ||
// Get the card element | ||
const card = document.getElementById('card'); | ||
const maxTilt = 10; // Maximum skew in degrees | ||
const transitionSpeed = 200; // Transition duration in ms | ||
|
||
// Add transition to the card for smoothness | ||
card.style.transition = `transform ${transitionSpeed}ms ease-out`; | ||
|
||
document.addEventListener('mousemove', (e) => { | ||
const { innerWidth, innerHeight } = window; | ||
const x = e.clientX - innerWidth / 2; | ||
const y = e.clientY - innerHeight / 2; | ||
// Calculate skew angles based on cursor position | ||
const skewY = (x / (innerWidth / 2)) * maxTilt; // Left-right | ||
const skewX = -(y / (innerHeight / 2)) * maxTilt; // Top-bottom | ||
// Apply the skew transform | ||
card.style.transform = `skew(${skewX}deg, ${skewY}deg) translate(-50%, -50%)`; | ||
|
||
// Calculate tilt angles based on cursor position | ||
const tiltY = (x / (innerWidth / 2)) * maxTilt; // Left-right | ||
const tiltX = -(y / (innerHeight / 2)) * maxTilt; // Top-bottom | ||
|
||
// Apply the tilt transform | ||
card.style.transform = `perspective(1000px) rotateX(${tiltX}deg) rotateY(${tiltY}deg) translate(-50%, -50%)`; | ||
}); | ||
// Reset skew when mouse leaves the window | ||
|
||
// Reset tilt when mouse leaves the window | ||
document.addEventListener('mouseleave', () => { | ||
card.style.transform = `skew(0deg, 0deg)`; | ||
card.style.transform = `perspective(1000px) rotateX(0deg) rotateY(0deg) translate(-50%, -50%)`; | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters