Jump to content

Bedford- Sticky header change opacity or color as page is scrolled

Recommended Posts

Site URL: http://www.peakwalkerpdx.com

Hi I currently have CSS installed on my page so that when scrolled through, the header follows along stuck at the top of the browser window. I would like for the header background color to be transparent over a banner image and then increase in opacity once it is scrolled past the banner image. Can anyone share coding to do this?

This is the CSS currently installed to make the banner sticky and fix the overlap onto the main page:

header#header {
position: fixed !important;
left: 0;
right: 0;
top: 0;
z-index: 999;
}
main#page {
margin-top: 80px;
}
Edited by Peakwalker
Link to comment
1 hour ago, Peakwalker said:

Site URL: http://www.peakwalkerpdx.com

Hi I currently have CSS installed on my page so that when scrolled through, the header follows along stuck at the top of the browser window. I would like for the header background color to be transparent over a banner image and then increase in opacity once it is scrolled past the banner image. Can anyone share coding to do this?

This is the CSS currently installed to make the banner sticky and fix the overlap onto the main page:

header#header {
position: fixed !important;
left: 0;
right: 0;
top: 0;
z-index: 999;
}
main#page {
margin-top: 80px;
}

Add this into page code injection to enable a scroll-wise animation

<script src="//cdnjs.cloudflare.com/ajax/libs/ScrollMagic/2.0.7/ScrollMagic.min.js"></script>
<style>
#header {
  transition: all 0.5s;
}
.header-transparent{
  background-color: transparent !important;
}
</style>
<script>
  document.addEventListener('DOMContentLoaded', function() {
      var controller = new ScrollMagic.Controller();
      var myScene = new ScrollMagic.Scene().addTo(controller);
      var scene = new ScrollMagic.Scene({
              triggerElement: "#block-yui_3_17_2_1_1563832386099_11359",
              triggerHook: 0,
              duration: document.querySelector("#block-yui_3_17_2_1_1563832386099_11359").clientHeight
          })
            .setClassToggle('#header', 'header-transparent')
            .reverse(true)
            .addTo(controller);
});
</script>

the text "#block-yui_3_17_2_1_1563832386099_11359" is unique id of the block you want the the header transparent, find it using: Squarespace ID Finder - Chrome Web Store (google.com)

image.thumb.png.478811b0871f88ea9d0e6aa3c1d06439.png

BeyondSpace - Squarespace Website Developer

🖼️ Lightbox Studio (Enable Pinch/Zoom on lightbox)
🗓️ Delivery Date Picker (Squarespace Date format)
💫 Animated Buttons (Referral URL)
🥳 Sparkplugin Customisations Browsers (Browse +100 Spark plugin customisations)
🥳 Elfsight Template Browsers (Browse +1000 Elfsight widget Templates)

If you find my answer useful, let's leave a like or upvote so others with the same issue can find their solution. 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.