Skip to content

Commit

Permalink
Fixed card shimmer
Browse files Browse the repository at this point in the history
  • Loading branch information
QuiteAFancyEmerald committed Jul 8, 2024
1 parent fe43d02 commit 9e17799
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 30 deletions.
16 changes: 0 additions & 16 deletions vercel.json

This file was deleted.

30 changes: 16 additions & 14 deletions views/assets/js/card.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,31 @@
/* Card Shimmer Mouse Follow Script
/* ----------------------------------------------- */

const shimmerEffects = document.querySelectorAll(".box-card");

// Attach CSS variables, mouse-x and mouse-y, to elements that will be
// given shimmer effects, by adding or modifying the style attribute.
// CSS calculates and renders the actual shimmer effect from there.
shimmerEffects.forEach(shimmerEffect => {
shimmerEffect.addEventListener("mousemove", handleMouseMove);
shimmerEffect.addEventListener("mouseleave", handleMouseLeave);
});

// Function declarations
// Track the cursor position with respect to the top left of the card.
// The "this" keyword gets the element that invoked the event listener.
const handleMouseMove = e => {
function handleMouseMove(e) {
const rect = this.getBoundingClientRect();
const x = e.clientX - rect.left;
const y = e.clientY - rect.top;

this.style.setProperty("--mouse-x", `${x}px`);
this.style.setProperty("--mouse-y", `${y}px`);
};
}

// Reset the cursor tracking variables when the cursor leaves the card.
const handleMouseLeave = () => {
function handleMouseLeave() {
this.style.setProperty("--mouse-x", `50%`);
this.style.setProperty("--mouse-y", `50%`);
};
}

// Query and add event listeners
const shimmerEffects = document.querySelectorAll(".box-card");

// Attach CSS variables, mouse-x and mouse-y, to elements that will be
// given shimmer effects, by adding or modifying the style attribute.
// CSS calculates and renders the actual shimmer effect from there.
shimmerEffects.forEach(shimmerEffect => {
shimmerEffect.addEventListener("mousemove", handleMouseMove);
shimmerEffect.addEventListener("mouseleave", handleMouseLeave);
});

0 comments on commit 9e17799

Please sign in to comment.