Try Shopify for free, and explore all the tools and services you need to start, run, and grow your business.

How To Make Dawn Sticky Header Permanent

Quick and easy guide below, currently the Dawn theme has the sticky header option, but only reveals itself when you scroll up. So this guide will teach you how to make the sticky header function permanent.


Change Header.Liquid And Put Code In Global.js

Go to edit code, head over to the Section folder and find header.liquid. Once found, scroll down until you find the below code. It’s essentially everything between the {% javascript %} {% endjavascript %} tags, before the {% schema %} tag. Delete it from the header.liquid.



{% javascript %}

  class StickyHeader extends HTMLElement {

    constructor() {

      super();

    }


    connectedCallback() {

      this.header = document.getElementById('shopify-section-header');

      this.headerBounds = {};

      this.currentScrollTop = 0;

      this.preventReveal = false;

      this.predictiveSearch = this.querySelector('predictive-search');


      this.onScrollHandler = this.onScroll.bind(this);

      this.hideHeaderOnScrollUp = () => this.preventReveal = true;


      this.addEventListener('preventHeaderReveal', this.hideHeaderOnScrollUp);

      window.addEventListener('scroll', this.onScrollHandler, false);


      this.createObserver();

    }


    disconnectedCallback() {

      this.removeEventListener('preventHeaderReveal', this.hideHeaderOnScrollUp);

      window.removeEventListener('scroll', this.onScrollHandler);

    }


    createObserver() {

      let observer = new IntersectionObserver((entries, observer) => {

        this.headerBounds = entries[0].intersectionRect;

        observer.disconnect();

      });


      observer.observe(this.header);

    }


    onScroll() {

      const scrollTop = window.pageYOffset || document.documentElement.scrollTop;


      if (this.predictiveSearch && this.predictiveSearch.isOpen) return;


      if (scrollTop > this.currentScrollTop && scrollTop > this.headerBounds.bottom) {

        requestAnimationFrame(this.hide.bind(this));

      } else if (scrollTop < this.currentScrollTop && scrollTop > this.headerBounds.bottom) {

        if (!this.preventReveal) {

          requestAnimationFrame(this.reveal.bind(this));

        } else {

          window.clearTimeout(this.isScrolling);


          this.isScrolling = setTimeout(() => {

            this.preventReveal = false;

          }, 66);


          requestAnimationFrame(this.hide.bind(this));

        }

      } else if (scrollTop <= this.headerBounds.top) {

        requestAnimationFrame(this.reset.bind(this));

      }



      this.currentScrollTop = scrollTop;

    }


    hide() {

      this.header.classList.add('shopify-section-header-hidden', 'shopify-section-header-sticky');

      this.closeMenuDisclosure();

      this.closeSearchModal();

    }


    reveal() {

      this.header.classList.add('shopify-section-header-sticky', 'animate');

      this.header.classList.remove('shopify-section-header-hidden');

    }


    reset() {

      this.header.classList.remove('shopify-section-header-hidden', 'shopify-section-header-sticky', 'animate');

    }


    closeMenuDisclosure() {

      this.disclosures = this.disclosures || this.header.querySelectorAll('details-disclosure');

      this.disclosures.forEach(disclosure => disclosure.close());

    }


    closeSearchModal() {

      this.searchModal = this.searchModal || this.header.querySelector('details-modal');

      this.searchModal.close(false);

    }

  }


  customElements.define('sticky-header', StickyHeader);

{% endjavascript %}

Go to the Asset Folder and find Global.js, go to the very bottom of Global.js, copy the below code and paste it.



class StickyHeader extends HTMLElement {

  constructor() {

    super();

  }


  connectedCallback() {

    this.header = document.getElementById('shopify-section-header');

    this.header.classList.add('shopify-section-header-sticky');

    this.headerBounds = {};

    this.currentScrollTop = 0;

    this.preventReveal = false;

    this.predictiveSearch = this.querySelector('predictive-search');


    this.onScrollHandler = this.onScroll.bind(this);

    this.hideHeaderOnScrollUp = () => this.preventReveal = true;


    this.addEventListener('preventHeaderReveal', this.hideHeaderOnScrollUp);

    window.addEventListener('scroll', this.onScrollHandler, false);


    this.createObserver();

  }


  disconnectedCallback() {

    this.removeEventListener('preventHeaderReveal', this.hideHeaderOnScrollUp);

    window.removeEventListener('scroll', this.onScrollHandler);

  }


  createObserver() {

    let observer = new IntersectionObserver((entries, observer) => {

      this.headerBounds = entries[0].intersectionRect;

      observer.disconnect();

    });


    observer.observe(this.header);

  }


  onScroll() {

    const scrollTop = window.pageYOffset || document.documentElement.scrollTop;


    if (this.predictiveSearch && this.predictiveSearch.isOpen) return;

    /*

    if (scrollTop > this.currentScrollTop && scrollTop > this.headerBounds.bottom) {

      requestAnimationFrame(this.hide.bind(this));

    } else if (scrollTop < this.currentScrollTop && scrollTop > this.headerBounds.bottom) {

      if (!this.preventReveal) {

        requestAnimationFrame(this.reveal.bind(this));

      } else {

        window.clearTimeout(this.isScrolling);


        this.isScrolling = setTimeout(() => {

                                      this.preventReveal = false;

                                      }, 66);


        requestAnimationFrame(this.hide.bind(this));

      }

    } else if (scrollTop <= this.headerBounds.top) {

      requestAnimationFrame(this.reset.bind(this));

    }

    */



    this.currentScrollTop = scrollTop;

  }


  /*

  hide() {

    this.header.classList.add('shopify-section-header-hidden', 'shopify-section-header-sticky');

    this.closeMenuDisclosure();

    this.closeSearchModal();

  }


  reveal() {

    this.header.classList.add('shopify-section-header-sticky', 'animate');

    this.header.classList.remove('shopify-section-header-hidden');

  }


  reset() {

    this.header.classList.remove('shopify-section-header-hidden', 'shopify-section-header-sticky', 'animate');

  }

  */


  closeMenuDisclosure() {

    this.disclosures = this.disclosures || this.header.querySelectorAll('details-disclosure');

    this.disclosures.forEach(disclosure => disclosure.close());

  }


  closeSearchModal() {

    this.searchModal = this.searchModal || this.header.querySelector('details-modal');

    this.searchModal.close(false);

  }

}


 customElements.define('sticky-header', StickyHeader);

And you are done, you now have a permanent sticky header without the nasty animation on the Dawn theme! 

How To Make Dawn Sticky Header Permanent How To Make Dawn Sticky Header Permanent Reviewed by Navjeet Singh on April 10, 2026 Rating: 5

No comments:

Powered by Blogger.