Created
June 16, 2022 17:32
-
-
Save mattsims/bf32d6b5a1f1ba92e4c8a4db7389cfc9 to your computer and use it in GitHub Desktop.
Various snippets useful for Webflow development
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<style type="text/css"> | |
.no-scroll { | |
overflow: hidden; | |
height: 100%; | |
} | |
</style> | |
<script type="text/javascript"> | |
var Webflow = Webflow || []; | |
Webflow.push(function () { | |
// Add class to fixed/sticky header once it reaches first content | |
let contentElement = $("#first_content"); | |
let headerElement = $(".navbar_component"); | |
console.log(`${contentElement.outerHeight() + headerElement.outerHeight()}px`); | |
let observer = new IntersectionObserver(entries => { | |
if (entries[0].isIntersecting) { | |
headerElement.removeClass("with-background"); | |
} else { | |
headerElement.addClass("with-background"); | |
} | |
}, { | |
rootMargin: `-${contentElement.outerHeight() + headerElement.outerHeight()}px`, | |
}); | |
observer.observe(contentElement[0]); | |
// Prevent page scroll while mobile nav open | |
$('.w-nav-button').on('click', function() { | |
$('body').toggleClass('no-scroll'); | |
}); | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment