forked from apu52/Travel_Website
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mouseEffect.js
27 lines (22 loc) · 837 Bytes
/
mouseEffect.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
document.addEventListener('mousemove', function(event) {
const ripple = document.createElement('div');
const element = document.getElementById('top');
let x = event.clientX;
let y = event.clientY;
let scrollLeft = window.pageXOffset;
let scrollTop = window.pageYOffset;
ripple.className = 'ripple';
let relativeX = x + scrollLeft;
let relativeY = y + scrollTop;
ripple.style.left = `${relativeX - 5}px`;
ripple.style.top = `${relativeY - 5}px`;
document.body.appendChild(ripple);
// Trigger the animation by adding the class after a short delay
setTimeout(() => {
ripple.classList.add('ripple-active');
}, 10);
// Remove the ripple element after the animation ends
ripple.addEventListener('transitionend', () => {
ripple.remove();
});
});