Initial commit xmarticaims
This commit is contained in:
@@ -0,0 +1,74 @@
|
||||
import { animate } from '../../assets/vendor/animejs/modules/animation/index.js';
|
||||
import { remove, set } from '../../assets/vendor/animejs/modules/utils/index.js';
|
||||
|
||||
const cards = document.querySelectorAll('#tecnologias .platform-marquee__card');
|
||||
const canTilt = window.matchMedia('(hover: hover) and (pointer: fine)').matches;
|
||||
const reduceMotion = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
|
||||
|
||||
if (cards.length && canTilt && !reduceMotion) {
|
||||
cards.forEach((card) => {
|
||||
const maxRotation = 7;
|
||||
let bounds = null;
|
||||
let frame = 0;
|
||||
let pointerX = 0;
|
||||
let pointerY = 0;
|
||||
|
||||
set(card, { rotateX: 0, rotateY: 0, scale: 1 });
|
||||
card.classList.add('platform-card-tilt-ready');
|
||||
|
||||
const renderTilt = () => {
|
||||
frame = 0;
|
||||
|
||||
if (!bounds) {
|
||||
return;
|
||||
}
|
||||
|
||||
const normalizedX = Math.max(-1, Math.min(1, ((pointerX - bounds.left) / bounds.width) * 2 - 1));
|
||||
const normalizedY = Math.max(-1, Math.min(1, ((pointerY - bounds.top) / bounds.height) * 2 - 1));
|
||||
|
||||
remove(card);
|
||||
animate(card, {
|
||||
rotateX: normalizedY * -maxRotation,
|
||||
rotateY: normalizedX * maxRotation,
|
||||
scale: 1.055,
|
||||
duration: 320,
|
||||
ease: 'out(3)',
|
||||
});
|
||||
};
|
||||
|
||||
card.addEventListener('pointerenter', (event) => {
|
||||
bounds = card.getBoundingClientRect();
|
||||
pointerX = event.clientX;
|
||||
pointerY = event.clientY;
|
||||
card.classList.add('is-platform-tilting');
|
||||
renderTilt();
|
||||
});
|
||||
|
||||
card.addEventListener('pointermove', (event) => {
|
||||
pointerX = event.clientX;
|
||||
pointerY = event.clientY;
|
||||
|
||||
if (!frame) {
|
||||
frame = window.requestAnimationFrame(renderTilt);
|
||||
}
|
||||
});
|
||||
|
||||
card.addEventListener('pointerleave', () => {
|
||||
if (frame) {
|
||||
window.cancelAnimationFrame(frame);
|
||||
frame = 0;
|
||||
}
|
||||
|
||||
bounds = null;
|
||||
card.classList.remove('is-platform-tilting');
|
||||
remove(card);
|
||||
animate(card, {
|
||||
rotateX: 0,
|
||||
rotateY: 0,
|
||||
scale: 1,
|
||||
duration: 620,
|
||||
ease: 'out(4)',
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user