Code

Shadow navbar on Scroll

Emphasize your navbar by adding a shadow on page scroll for your Webflow site. This effect you can use via interactions although an easier way is to add a simple Javascript snippet instead. The code makes it so that if a user hasn't scrolled then no shadow…

Shadow navbar on Scroll preview

Emphasize your navbar by adding a shadow on page scroll for your Webflow site. This effect you can use via interactions although an easier way is to add a simple Javascript snippet instead. The code makes it so that if a user hasn't scrolled then no shadow will be visible. When a user scrolls your shadow effect will then be added.

How to add it

  1. Add the Javascript snippet to your closing body tag of custom code
  2. Update the element ID of main-navigation to your chosen element ID
  3. You can update settings such as Vertical movement (how far down someone has scrolled), Blur and other effects based on your needs.

The code

Javascript
                      <!-- Add to closing body tag -->
<script>
let navContent = document.getElementById('main-navigation');
$(window).scroll(function() {    
if($(window).scrollTop() > 0) {        
navContent.style.boxShadow = '0 1px 0px #e8e9ee';
navContent.style.transition = 'all 0.2s';    
} else {        
navContent.style.boxShadow = '0 0 0 rgba(0, 0, 0, 0)';
navContent.style.transition = 'all 0.2s';  
}
});
</script>

                    

Browse similar code snippets

Language

More from Nikolai Bain

Profile →

Related Webflow questions

All answers →

Similar code snippets

All code snippets →