Skip to content

Commit 68ddc55

Browse files
committed
Day 22 complete
1 parent 028c719 commit 68ddc55

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

β€Ž22 - Follow Along Link Highlighter/index.htmlβ€Ž

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,29 @@
2626
</div>
2727

2828
<script>
29-
// πŸ‘€πŸ‘€πŸ‘€πŸ‘€πŸ‘€πŸ‘€πŸ‘€πŸ‘€πŸ‘€πŸ‘€πŸ‘€πŸ‘€πŸ‘€πŸ‘€πŸ‘€
29+
const links = document.querySelectorAll('a');
30+
const highlight = document.createElement('span');
31+
32+
highlight.classList.add('highlight');
33+
document.body.append(highlight);
34+
35+
function hilightLink() {
36+
const linkBox = this.getBoundingClientRect();
37+
const coords = {
38+
width: linkBox.width,
39+
height: linkBox.height,
40+
top: linkBox.top + window.scrollY,
41+
left: linkBox.left + window.scrollX
42+
};
43+
44+
highlight.style.width = `${coords.width}px`;
45+
highlight.style.height = `${coords.height}px`;
46+
highlight.style.transform = `translate(${coords.left}px, ${coords.top}px)`;
47+
}
48+
49+
links.forEach(a => a.addEventListener('mouseenter', hilightLink));
50+
51+
3052
</script>
3153
</body>
3254
</html>
33-

0 commit comments

Comments
Β (0)