Skip to content

Commit 2276202

Browse files
author
Kyle Bradshaw
committed
21 follow link animation
1 parent 80beae9 commit 2276202

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

22 - Follow Along Link Highlighter/index-START.html renamed to 22 - Follow Along Link Highlighter/index.html

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,28 @@
2727

2828
<script>
2929
// 👀👀👀👀👀👀👀👀👀👀👀👀👀👀👀
30+
const triggers = document.querySelectorAll('a');
31+
const highlight = document.createElement('span');
32+
highlight.classList.add('highlight');
33+
document.body.append(highlight);
34+
35+
function highlightLink() {
36+
const linkCoords = this.getBoundingClientRect();
37+
const coords = {
38+
width: linkCoords.width,
39+
height: linkCoords.height,
40+
top: linkCoords.top + window.scrollY,
41+
left: linkCoords.left + window.scrollX,
42+
}
43+
console.log(this, linkCoords)
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+
//fix the offset of window.scrollY
49+
}
50+
51+
triggers.forEach(a => a.addEventListener('mouseenter', highlightLink));
3052
</script>
3153
</body>
3254
</html>

0 commit comments

Comments
 (0)