Path: blob/master/views/assets/js/card.js
5247 views
/* -----------------------------------------------1/* Authors: QuiteAFancyEmerald2/* GNU Affero General Public License v3.0: https://www.gnu.org/licenses/agpl-3.0.en.html3/* Card Shimmer Mouse Follow Script4/* ----------------------------------------------- */56// Encase everything in a new scope so that variables are not accidentally7// attached to the global scope.8(() => {9// Track the cursor position with respect to the top left of the card.10// The "this" keyword gets the element that invoked the event listener.11const handleMouseMove = (element) => {12element.addEventListener('mousemove', (e) => {13const rect = element.getBoundingClientRect();14const x = e.clientX - rect.left;15const y = e.clientY - rect.top;1617element.style.setProperty('--mouse-x', `${x}px`);18element.style.setProperty('--mouse-y', `${y}px`);19});20},21// Reset the cursor tracking variables when the cursor leaves the card.22handleMouseLeave = (element) => {23element.addEventListener('mouseleave', () => {24element.style.setProperty('--mouse-x', `50%`);25element.style.setProperty('--mouse-y', `50%`);26});27},28// Get the box card elements and add the event listeners to them.29shimmerEffects = document.querySelectorAll('.box-card, .box-hero');3031/* Attach CSS variables, mouse-x and mouse-y, to elements that will be32* given shimmer effects, by adding or modifying the style attribute.33* CSS calculates and renders the actual shimmer effect from there.34*/35shimmerEffects.forEach(handleMouseMove);36shimmerEffects.forEach(handleMouseLeave);37})();383940