Skip to content

Commit 82c4871

Browse files
committed
Completed lesson 24
Not feeling completely lost…yet.
1 parent 52bc0ac commit 82c4871

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

24 - Sticky Nav/index-START.html

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,18 @@ <h1>A story about getting lost.</h1>
5454
</div>
5555

5656
<script>
57-
57+
const nav = document.querySelector('#main');
58+
const topOfNav = nav.offsetTop;
59+
function fixNav() {
60+
if (window.scrollY >= topOfNav) {
61+
document.body.style.paddingTop = nav.offsetHeight + 'px';
62+
document.body.classList.add('fixed-nav');
63+
} else {
64+
document.body.style.paddingTop = 0;
65+
document.body.classList.remove('fixed-nav');
66+
}
67+
}
68+
window.addEventListener('scroll', fixNav);
5869
</script>
5970

6071
</body>

24 - Sticky Nav/style-START.css

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ body {
2323
transition: transform 0.5s;
2424
}
2525

26+
.fixed-nav .site-wrap {
27+
transform: scale(1);
28+
}
29+
2630
header {
2731
text-align: center;
2832
height:50vh;
@@ -48,6 +52,11 @@ nav {
4852
z-index: 1;
4953
}
5054

55+
.fixed-nav nav {
56+
position: fixed;
57+
box-shadow: 0 5px rgba(0,0,0,0.1);
58+
}
59+
5160
nav ul {
5261
margin: 0;
5362
padding:0;
@@ -72,6 +81,10 @@ li.logo {
7281
font-size: 30px;
7382
}
7483

84+
.fixed-nav li.logo {
85+
max-width: 500px;
86+
}
87+
7588
li.logo a {
7689
color:black;
7790
}

0 commit comments

Comments
 (0)