I am attempting to create a sticky navbar that stays at the top of the page once the header has been scrolled past. It should have a similar effect as shown in this example on codepen.io, but with the addition of an image that stretches across most of the screen and adjusts dynamically based on the window size. Instead of setting a fixed point for the navbar to stick after scrolling a certain distance, I need a Javascript function that triggers the sticking effect when reaching the bottom of any element.
Here is the HTML:
<header>
<img src="https://upload.wikimedia.org/wikipedia/commons/d/de/Mount_Shuksan,_Picture_Lake_(2362739742).jpg" alt="">
</header>
<nav id = "nav_bar">
<ul class = "navbar-list">
<li>
<a href="">link1</a>
</li>
<li class="dropdown">
<a href="#" class="dropbtn">link2</a>
<div class="dropdown-content">
<a href="#">link 1</a>
<a href="#">link 2</a>
<a href="#">link 3</a>
<a href="">link 4</a>
</div>
</li>
<li>
<a href="">link 3</a>
</li>
<li>
<a href="">link4</a>
</li>
</ul>
</nav>
<body>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</p>
<p>
Lorem ipsum dolor...
CSS:
...This updated version also includes a sample image overlapping the header for better visualization: codepen.io.