The code below will add a class to the position:sticky element when it intersects with the assigned element (in the last line of the code). Depending on your HTML structure, you might have to try different elements to target. In this example, the sticky navbar is a direct sibling - this is usually the best way to make this work. I couldn't get this to work if I targeted .site-header.
You can also remove all the Drupal wrapper js code, and just use the code between the "=====" lines, if you're not in Drupal.
<header class="site-header"></header>
<main>
<div class="wrapper">