Skip to content

Commit 43e9b8d

Browse files
committed
Sticky Navigation Bar
1 parent 1a532b9 commit 43e9b8d

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

starter/09-Omnifood-Optimizations/css/style.css

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,24 @@
7676
display: none;
7777
}
7878

79+
/* Sticky navigation */
80+
.sticky .header {
81+
position: fixed;
82+
top: 0;
83+
bottom: 0;
84+
width: 100%;
85+
height: 8rem;
86+
padding-top: 0;
87+
padding-bottom: 0;
88+
background-color: rgba(255, 255, 255, 0.97);
89+
z-index: 999;
90+
box-shadow: 0 1.2rem 3.2rem rgba(0, 0, 0, 0.03);
91+
}
92+
93+
.sticky .section-hero {
94+
margin-top: 9.6rem;
95+
}
96+
7997
/**************************/
8098
/* HERO SECTION */
8199
/**************************/

starter/09-Omnifood-Optimizations/js/script.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,27 @@ allLinks.forEach(function (link) {
3939
});
4040
});
4141

42+
//Sticky navigation
43+
44+
const sectionHeroEl = document.querySelector(".section-hero");
45+
const obs = new IntersectionObserver(
46+
function (entries) {
47+
const ent = entries[0];
48+
if (!ent.isIntersecting) {
49+
document.body.classList.add("sticky");
50+
}
51+
if (ent.isIntersecting) {
52+
document.body.classList.remove("sticky");
53+
}
54+
},
55+
{
56+
root: null,
57+
threshold: 0,
58+
rootMargin: "-80px",
59+
}
60+
);
61+
obs.observe(sectionHeroEl);
62+
4263
///////////////////////////////////////////////////////////
4364
// Fixing flexbox gap property missing in some Safari versions
4465
function checkFlexGap() {

0 commit comments

Comments
 (0)