-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
28 lines (21 loc) · 888 Bytes
/
main.js
File metadata and controls
28 lines (21 loc) · 888 Bytes
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
28
const horizontal = document.querySelector('.horizontal');
const vertical = document.querySelector('.vertical');
const target = document.querySelector('.target');
const tag = document.querySelector('.tag');
window.addEventListener('load', () => {
const targetRect = target.getBoundingClientRect();
const targetHalfWidth = targetRect.width / 2;
const targetHalfHeight = targetRect.height / 2;
document.addEventListener('mousemove', (e) => {
const x = e.clientX;
const y = e.clientY;
vertical.style.transform = `translateX(${x}px)`;
horizontal.style.transform = `translateY(${y}px)`;
target.style.transform = `translate(${x}px,${y}px)`;
target.style.transform = `translate(${x - targetHalfWidth}px, ${
y - targetHalfHeight
}px)`;
tag.style.transform = `translate(${x + 20}px,${y + 20}px)`;
tag.innerHTML = `${x}px, ${y}px`;
});
});