-
Notifications
You must be signed in to change notification settings - Fork 0
/
cards.js
37 lines (29 loc) · 1.13 KB
/
cards.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
document.getElementById("cards").addEventListener("mousemove", handleMouseMove);
document.getElementById("cards").addEventListener("touchmove", handleTouchMove);
function handleMouseMove(e) {
for (const card of document.getElementsByClassName("card")) {
updateCardPosition(card, e.clientX, e.clientY);
}
}
function handleTouchMove(e) {
for (const card of document.getElementsByClassName("card")) {
updateCardPosition(card, e.touches[0].clientX, e.touches[0].clientY);
}
}
function updateCardPosition(card, clientX, clientY) {
const rect = card.getBoundingClientRect();
const x = clientX - rect.left;
const y = clientY - rect.top;
card.style.setProperty("--mouse-x", `${x}px`);
card.style.setProperty("--mouse-y", `${y}px`);
}
// const cards = document.getElementById('cards');
// function showCardsOnScroll() {
// const cardsTop = cards.getBoundingClientRect().top;
// const windowHeight = window.innerHeight;
// if (cardsTop > windowHeight * 0.9) {
// cards.classList.add('show');
// window.removeEventListener('scroll', showCardsOnScroll);
// }
// }
// window.addEventListener('scroll', showCardsOnScroll);