Skip to content

Commit f0c4f41

Browse files
committed
Section 9 - Sticky Navigation Bar
1 parent 8fa0728 commit f0c4f41

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

starter/07-Omnifood-Desktop/css/style.css

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,24 @@
3636
display: none;
3737
}
3838

39+
.sticky .header {
40+
position: fixed;
41+
top: 0;
42+
bottom: 0;
43+
width: 100%;
44+
height: 8rem;
45+
padding-top: 0;
46+
padding-bottom: 0;
47+
background-color: rgba(255, 255, 255, 0.97);
48+
z-index: 999;
49+
box-shadow: 0 1.2rem 3.2rem rgba(0, 0, 0, 0.03);
50+
}
51+
52+
.sticky .section-hero {
53+
/* offset for the difference when removing the header from flow */
54+
margin-top: 9.6rem;
55+
}
56+
3957
/**********************/
4058
/* NAVIGATION */
4159
/**********************/

starter/07-Omnifood-Desktop/js/script.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,25 @@ allLinks.forEach((link) => {
3737
});
3838
});
3939

40+
// Sticky navigation
41+
const observer = new IntersectionObserver(
42+
function (entries) {
43+
if (!entries[0].isIntersecting) {
44+
document.body.classList.add("sticky");
45+
} else {
46+
document.body.classList.remove("sticky");
47+
}
48+
},
49+
{
50+
// In the viewport
51+
root: null,
52+
// How much of the observed element is in the view port
53+
threshold: 0,
54+
rootMargin: "-80px",
55+
}
56+
);
57+
observer.observe(document.querySelector(".section-hero"));
58+
4059
///////////////////////////////////////////////////////////
4160
// Fixing flexbox gap property missing in some Safari versions
4261
function checkFlexGap() {

0 commit comments

Comments
 (0)