Visitar URL original
The last half! by LHJE · Pull Request #5 · LHJE/JavaScript30 · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update 24 with logic from tutorial
  • Loading branch information
LHJE committed Jul 7, 2021
commit 35bb7f003f8d7daed5f1b52cc0f98932e4629565
15 changes: 15 additions & 0 deletions 24 - Sticky Nav/index-START.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,21 @@ <h1>A story about getting lost.</h1>

<script>

const nav = document.querySelector('#main')
const topOfNav = nav.offsetTop;

function fixNav(){
if(window.scrollY >= topOfNav){
document.body.style.paddingTop = nav.offsetHeight + 'px';
document.body.classList.add('fixed-nav');
} else {
document.body.style.paddingTop = 0;
document.body.classList.remove('fixed-nav')
}
}

window.addEventListener('scroll', fixNav);

</script>

</body>
Expand Down
13 changes: 13 additions & 0 deletions 24 - Sticky Nav/style-START.css
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,19 @@ nav {
z-index: 1;
}

.fixed-nav li.logo {
max-width: 500px;
}

.fixed-nav .site-wrap {
transform: scale(1);
}

.fixed-nav nav {
position: fixed;
box-shadow: 0 5px rgba(0,0,0,0.1);
}

nav ul {
margin: 0;
padding:0;
Expand Down