Skip to content

Commit bacb6e1

Browse files
committed
Complete Day 22 - Follow Along Link Highlighter
1 parent 9c2abd0 commit bacb6e1

3 files changed

Lines changed: 28 additions & 63 deletions

File tree

22 - Follow Along Link Highlighter/index-FINISHED.html

Lines changed: 0 additions & 56 deletions
This file was deleted.

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

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,28 @@
2727
</div>
2828

2929
<script>
30-
// 👀👀👀👀👀👀👀👀👀👀👀👀👀👀👀
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+
console.log(linkCoords);
38+
const coords = {
39+
width: linkCoords.width,
40+
height: linkCoords.height,
41+
top: linkCoords.top + window.scrollY,
42+
left: linkCoords.left + window.scrollX,
43+
}
44+
45+
highlight.style.width = `${coords.width}px`;
46+
highlight.style.height = `${coords.height}px`;
47+
highlight.style.transform = `translate(${coords.left}px, ${coords.top}px)`;
48+
}
49+
50+
triggers.forEach(a => a.addEventListener('mouseenter', highlightLink));
51+
3152
</script>
3253
</body>
3354
</html>

22 - Follow Along Link Highlighter/style.css

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ body {
1111
margin: 0; /* Important! */
1212
font-family: sans-serif;
1313
background:
14-
linear-gradient(45deg, hsla(340, 100%, 55%, 1) 0%, hsla(340, 100%, 55%, 0) 70%),
15-
linear-gradient(135deg, hsla(225, 95%, 50%, 1) 10%, hsla(225, 95%, 50%, 0) 80%),
16-
linear-gradient(225deg, hsla(140, 90%, 50%, 1) 10%, hsla(140, 90%, 50%, 0) 80%),
17-
linear-gradient(315deg, hsla(35, 95%, 55%, 1) 100%, hsla(35, 95%, 55%, 0) 70%);
14+
linear-gradient(45deg, rgb(26, 194, 255) 0%, hsla(340, 100%, 55%, 0) 70%),
15+
linear-gradient(135deg, rgb(106, 131, 161) 10%, hsla(225, 95%, 50%, 0) 80%),
16+
linear-gradient(225deg, rgb(61, 154, 182) 10%, hsla(140, 90%, 50%, 0) 80%),
17+
linear-gradient(315deg, rgb(77, 106, 156) 100%, hsla(35, 95%, 55%, 0) 70%);
1818
}
1919

2020
.wrapper {
@@ -34,10 +34,10 @@ a {
3434

3535
.highlight {
3636
transition: all 0.2s;
37-
border-bottom: 2px solid white;
37+
border-bottom: 2px solid rgb(27, 40, 65);
3838
position: absolute;
3939
top: 0;
40-
background: white;
40+
background: rgb(193, 244, 255);
4141
left: 0;
4242
z-index: -1;
4343
border-radius: 20px;

0 commit comments

Comments
 (0)