|
| 1 | +const card = document.querySelector(".card"); |
| 2 | +const cursor = document.querySelector(".custom-cursor"); |
| 3 | +const nameTag = document.querySelector(".name-tag"); |
| 4 | +const pointerIcon = document.querySelector(".cursor-icon"); |
| 5 | + |
| 6 | +const colorPairs = [ |
| 7 | + { primary: "#FF6B6B", secondary: "#4ECDC4" }, |
| 8 | + { primary: "#A17FB0", secondary: "#000" }, |
| 9 | + { primary: "#FF9F43", secondary: "#FF5E7D" }, |
| 10 | + { primary: "#00D2FF", secondary: "#f00" }, |
| 11 | + { primary: "#08AEEA", secondary: "#2AF598" }, |
| 12 | +]; |
| 13 | + |
| 14 | +function getRandomColorPair() { |
| 15 | + return colorPairs[Math.floor(Math.random() * colorPairs.length)]; |
| 16 | +} |
| 17 | + |
| 18 | +let colors = getRandomColorPair(); |
| 19 | + |
| 20 | +card.addEventListener("mouseenter", () => { |
| 21 | + colors = getRandomColorPair(); |
| 22 | + nameTag.style.backgroundColor = colors.secondary; |
| 23 | + pointerIcon.style.color = colors.secondary; |
| 24 | + |
| 25 | + gsap.to(cursor, { opacity: 1, duration: 0.1 }); |
| 26 | + gsap.to(nameTag, { scale: 1, duration: 0.3 }); |
| 27 | + card.style.border = `1px solid ${colors.secondary}`; |
| 28 | +}); |
| 29 | + |
| 30 | +card.addEventListener("mouseleave", () => { |
| 31 | + gsap.to(cursor, { opacity: 0, duration: 0.1 }); |
| 32 | + gsap.to(nameTag, { scale: 0, duration: 0.1 }); |
| 33 | + card.style.border = `1px solid #ccc`; |
| 34 | +}); |
| 35 | + |
| 36 | +card.addEventListener("mousemove", (e) => { |
| 37 | + const rect = card.getBoundingClientRect(); |
| 38 | + const x = e.clientX - rect.left; |
| 39 | + const y = e.clientY - rect.top; |
| 40 | + gsap.to(cursor, { x, y, duration: 0.1 }); |
| 41 | +}); |
0 commit comments