-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path22.js
21 lines (20 loc) · 862 Bytes
/
22.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
function followMe() {
const triggers = document.querySelectorAll("a");
const highlight = document.createElement("span");
highlight.classList.add("highlight");
document.body.append(highlight);
function highlightLinks() {
const linkCoords = this.getBoundingClientRect();
const coords = {
width: linkCoords.width,
height: linkCoords.height,
top: linkCoords.top + window.scrollY,
left: linkCoords.left + window.scrollX,
};
highlight.style.width = `${linkCoords.width}px`;
highlight.style.height = `${linkCoords.height}px`;
highlight.style.transform = `translate(${linkCoords.left}px, ${linkCoords.top}px)`;
}
triggers.forEach((a) => a.addEventListener("mouseenter", highlightLinks));
}
window.addEventListener("DOMContentLoaded", followMe);