Jump to content

7.0 creating a fixed header which shrinks while scrolling

Recommended Posts

  • Replies 1
  • Views 572
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

On 11/9/2021 at 10:33 PM, SUPevent said:

Site URL: https://www.sup-event.com/

Hey,

I would like to fix the header, but make it shrink and let the logo vanish when you scroll down.

Can you suggest some CSS Coding? I tried to look for answer here in the forum but I couldn't find anything that would work.

 

Thank you an nice greetings

Add to Settings > Advanced > Code Injection > Footer

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script>
$(function(){
 var visibleTop = 30;
  $(window).scroll(function() {
    var scroll = getCurrentScroll();
      if ( scroll >= visibleTop ) {
           $('header#header').addClass('tuan');
        }
        else {
            $('header#header').removeClass('tuan');
        }
  });
function getCurrentScroll() {
    return window.pageYOffset || document.documentElement.scrollTop;
    }
});
</script>
<style>
  header#header {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    z-index: 9999;
}
  header#header img {
  	transition: all 0.3s;
  }
  .tuan img {
    width: 50px !important;
    transition: all 0.3s;
}
</style>

 

Edited by tuanphan
missing closing tag

Email me if you have need any help (free, of course.). Answer within 24 hours. 
Or send to forum message

Contact Customer Care - Learn CSS - Buy me a coffee (thank you!)

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

×
×
  • Create New...

Squarespace Webinars

Free online sessions where you’ll learn the basics and refine your Squarespace skills.

Hire a Designer

Stand out online with the help of an experienced designer or developer.