Skip to content

Instantly share code, notes, and snippets.

@mattsims
Created June 16, 2022 17:32
Show Gist options
  • Save mattsims/bf32d6b5a1f1ba92e4c8a4db7389cfc9 to your computer and use it in GitHub Desktop.
Save mattsims/bf32d6b5a1f1ba92e4c8a4db7389cfc9 to your computer and use it in GitHub Desktop.
Various snippets useful for Webflow development
<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