Jump to content

how to make logo large in the hero, then as you scroll, it shrinks and remains in the navigation bar

Recommended Posts

  • Replies 6
  • Views 174
  • Created
  • Last Reply

Top Posters In This Topic

Posted

Try this:

 

Please like and upvote if my comments were helpful to you. Cheers!

Zygmunt Spray
Squarespace Website Designer
Contact me: 
https://squarefortytwo.com 
Hire me on Upwork!

📈 SEO Space (Referral link)
Ⓜ️ 
Will Myers' Plugins & Tutorials (Referral link)
 🔌 Ghost Squarespace Plugins (Referral link)
 SquareWebsites Plugins (Referral link)
 🔲SQSP Themes (Referral link) 
Spark Plugin (Referral link) 
 🖼️Pinch-to-Zoom Gallery Lightbox Plugin (Referral link) 

 Did I help? Buy me a coffee?

Posted

add the below code into custom css:

header-title-logo a img {
  transition: all 0.3s ease; /* Smooth transition for resizing */
  width: 150px; /* Large logo size for hero */
  height: auto;
}

header-title-logo.shrink a img {
  width: 50px; /* Smaller size for navbar */
  height: auto;
}

header.shrunk {
  padding: 10px 20px; /* Smaller padding when scrolled */
  background-color: rgba(255, 255, 255, 0.9); /* Optional: transparent background */
}

add the below code into pages > web tools > code injection > footer:

<script>
  document.addEventListener("DOMContentLoaded", function() {
    // Select the logo and the header
    const logo = document.querySelector('header-title-logo');
    const header = document.querySelector('header');

    // Function to handle scroll and apply/remove classes
    function handleScroll() {
      if (window.scrollY > 100) { // Adjust this threshold if needed
        logo.classList.add('shrink');  // Add 'shrink' class to the logo
        header.classList.add('shrunk'); // Optional: add a class to the header to modify styles
      } else {
        logo.classList.remove('shrink');  // Remove the 'shrink' class when scrolled up
        header.classList.remove('shrunk'); // Optional: reset header styles
      }
    }

    // Run the function on page load
    handleScroll();

    // Listen for scroll events
    window.addEventListener('scroll', handleScroll);
  });
</script>

 

Posted
7 hours ago, Squareko said:
header-title-logo a img {
  transition: all 0.3s ease; /* Smooth transition for resizing */
  width: 150px; /* Large logo size for hero */
  height: auto;
}

header-title-logo.shrink a img {
  width: 50px; /* Smaller size for navbar */
  height: auto;
}

header.shrunk {
  padding: 10px 20px; /* Smaller padding when scrolled */
  background-color: rgba(255, 255, 255, 0.9); /* Optional: transparent background */
}

This didn't work either 😕 the logo didn't change after applying both the codes above. I really appreciate your help though. Is there anything else you think would be helpful to try or settings I should check?

Posted (edited)
On 11/21/2024 at 1:01 AM, Squareko said:
header-title-logo a img {
  transition: all 0.3s ease; /* Smooth transition for resizing */
  width: 150px; /* Large logo size for hero */
  height: auto;
}

header-title-logo.shrink a img {
  width: 50px; /* Smaller size for navbar */
  height: auto;
}

header.shrunk {
  padding: 10px 20px; /* Smaller padding when scrolled */
  background-color: rgba(255, 255, 255, 0.9); /* Optional: transparent background */
}

@Ziggy I switched my header to 'fixed' and it works! Now the issue is:

1) It doesn't work on mobile. Is there CSS for mobile version?

2) Is there a way to do this when the header is not 'fixed'?

3) How do I have this only on the homepage?

4) [EDIT I may have fixed this one] When I change the screen size, the logo/header size doesn't adapt - for example, when I make the screen smaller, the logo goes down into the next section on the page.

Edited by StaceyArenson
Posted
On 11/23/2024 at 12:22 PM, StaceyArenson said:

I switched my header to 'fixed' and it works! Now the issue is:

1) It doesn't work on mobile. Is there CSS for mobile version?

2) Is there a way to do this when the header is not 'fixed'?

3) How do I have this only on the homepage?

4) [EDIT I may have fixed this one] When I change the screen size, the logo/header size doesn't adapt - for example, when I make the screen smaller, the logo goes down into the next section on the page.

There is a typo here

shrink

image.thumb.png.c75fe3a75a358f01788f4f2d91fdad66.png

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!)

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.