Skip to content

Commit d93d866

Browse files
committed
add function to shoe the shadow of the txt
1 parent 2c22707 commit d93d866

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

  • apps/mouse-move-shadow/assets/script
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
const container = document.querySelector(".container")
2+
const title = document.querySelector(".container__title")
3+
const walk = 500
4+
5+
const shadow = event => {
6+
const { offsetWidth: width, offsetHeight: height } = container;
7+
let { offsetX: x, offsetY: y } = event;
8+
9+
if (this !== event.target) {
10+
x = x + event.target.offsetLeft;
11+
y = y + event.target.offsetTop;
12+
}
13+
14+
const xWalk = Math.round((x / width * walk) - (walk / 2));
15+
const yWalk = Math.round((y / height * walk) - (walk / 2));
16+
title.style.textShadow = `
17+
${xWalk}px ${yWalk}px 0 rgba(255,0,255,0.7),
18+
${xWalk * -1}px ${yWalk}px 0 rgba(0,255,255,0.7),
19+
${yWalk}px ${xWalk * -1}px 0 rgba(0,255,0,0.7),
20+
${yWalk * -1}px ${xWalk}px 0 rgba(0,0,255,0.7)
21+
`;
22+
}
23+
24+
container.addEventListener('mousemove', shadow);

0 commit comments

Comments
 (0)