Change logo when a user scrolls down Dawn theme.

Change logo when a user scrolls down Dawn theme.

anirudh_singh
Shopify Partner
4 0 0

We are using Dawn Theme 10.0.0 and the store link is https://vogueorgy.myshopify.com/

 

We would like to use a different logo when as soon as a user scrolls down on the webpage. Something like on this website: https://bluorng.com/.

 

Thank you!

 

 

Replies 3 (3)

oscprofessional
Shopify Partner
16115 2409 3122

@anirudh_singh 
Hello,

To change the logo when a user scrolls down in a Shopify theme (such as the Dawn theme), you'll need to modify the theme's Liquid files. Here's a general approach to achieve this:

  1. Access your Shopify theme: Log in to your Shopify admin panel and navigate to the "Online Store" > "Themes" section. Locate the Dawn theme and click on the "Actions" button, then choose "Edit code" from the dropdown menu.

  2. Find the theme's header file: In the theme editor, locate the header file that controls the logo display. This file is usually named "header.liquid" or similar. Open this file in the code editor provided by the theme editor.

  3. Add a scroll event listener: Inside the header file, find the <header> section or the code responsible for rendering the logo. You'll need to add a scroll event listener to the JavaScript code to handle the logo change. Here's an example of how you can do this:

    liquid

 

<script>
  document.addEventListener('DOMContentLoaded', function() {
    var header = document.querySelector('.site-header');

    window.addEventListener('scroll', function() {
      // Add your logic to change the logo based on scroll position
      if (window.pageYOffset > 0) {
        // Change the logo when scrolled down
        header.classList.add('scrolled');
      } else {
        // Reset the logo to the original when scrolled back to the top
        header.classList.remove('scrolled');
      }
    });
  });
</script>

 

 

In this example, the code adds a CSS class "scrolled" to the header element when the user scrolls down. You'll need to define the appropriate CSS rules to change the logo when this class is present.

  • Define CSS styles: In the same header file or in a separate CSS file linked to the theme, add the necessary CSS styles to change the logo based on the "scrolled" class. Here's an example:

    css

 

/* Replace '.site-header' with the CSS selector for your header element */
.site-header {
  /* Styles for the default logo */
}

/* Replace '.site-header.scrolled' with the CSS selector for your header element with the 'scrolled' class */
.site-header.scrolled {
  /* Styles for the scrolled logo */
}

 

 

Customize the styles within the ".site-header.scrolled" block to display the desired logo when the user has scrolled down. You can adjust properties like background image, width, height, or any other relevant styles to achieve the desired effect.

  • Save and test: Save your changes in the theme editor and preview your website. As you scroll down, the logo in the header should change according to the applied styles.

Note: The exact file locations and code structure may vary depending on your specific theme. It's important to take backups and exercise caution when modifying theme files to avoid any unintended issues.

Get pass your Store Core Web Vital Free Speed Optimization Audit, Chat on WhatsApp | Skype : oscprofessionals-87 | Email: pallavi@oscprofessionals.com | Hire us | Guaranteed Site Speed Optimization | Website Free Audit | Shopify Theme Customization | Build Shopify Private App | Shopify SEO | Digital Marketing | Oscp Upsell & Cross sell App : Free | Oscp Sales & Volume Discount App : Free | Custom Pricing Wholesale App : Free
anirudh_singh
Shopify Partner
4 0 0

@oscprofessional 

This is the code related to header. Where do i place the script within this?

 

<header class="header header--{{ section.settings.logo_position }} header--mobile-{{ section.settings.mobile_logo_position }} page-width{% if section.settings.menu_type_desktop == 'drawer' %} drawer-menu{% endif %}{% if section.settings.menu != blank %} header--has-menu{% endif %}{% if has_app_block %} header--has-app{% endif %}{% if social_links %} header--has-social{% endif %}{% if shop.customer_accounts_enabled %} header--has-account{% endif %}{% if localization_forms %} header--has-localizations{% endif %}">
    {%- liquid
      if section.settings.menu != blank
        render 'header-drawer'
      endif

      if section.settings.logo_position == 'top-center' or section.settings.menu == blank
        render 'header-search', input_id: 'Search-In-Modal-1'
      endif
    -%}

    {%- if section.settings.logo_position != 'middle-center' -%}
      {%- if request.page_type == 'index' -%}
        <h1 class="header__heading">
      {%- endif -%}
          <a href="{{ routes.root_url }}" class="header__heading-link link link--text focus-inset">
            {%- if settings.logo != blank -%}
              <div class="header__heading-logo-wrapper">
                {%- assign logo_alt = settings.logo.alt | default: shop.name | escape -%}
                {%- assign logo_height = settings.logo_width | divided_by: settings.logo.aspect_ratio -%}
                {% capture sizes %}(max-width: {{ settings.logo_width | times: 2 }}px) 50vw, {{ settings.logo_width }}px{% endcapture %}
                {% capture widths %}{{ settings.logo_width }}, {{ settings.logo_width | times: 1.5 | round }}, {{ settings.logo_width | times: 2 }}{% endcapture %}
                {{ settings.logo | image_url: width: 600 | image_tag:
                  class: 'header__heading-logo motion-reduce',
                  widths: widths,
                  height: logo_height,
                  width: settings.logo_width,
                  alt: logo_alt,
                  sizes: sizes,
                  preload: true
                }}
              </div>
            {%- else -%}
              <span class="h2">{{ shop.name }}</span>
            {%- endif -%}
          </a>
      {%- if request.page_type == 'index' -%}
        </h1>
      {%- endif -%}
    {%- endif -%}

    {%- liquid
      if section.settings.menu != blank
        if section.settings.menu_type_desktop == 'dropdown'
          render 'header-dropdown-menu'
        elsif section.settings.menu_type_desktop != 'drawer'
          render 'header-mega-menu'
        endif
      endif
    %}

    {%- if section.settings.logo_position == 'middle-center' -%}
      {%- if request.page_type == 'index' -%}
        <h1 class="header__heading">
      {%- endif -%}
          <a href="{{ routes.root_url }}" class="header__heading-link link link--text focus-inset">
            {%- if settings.logo != blank -%}
              <div class="header__heading-logo-wrapper">
                {%- assign logo_alt = settings.logo.alt | default: shop.name | escape -%}
                {%- assign logo_height = settings.logo_width | divided_by: settings.logo.aspect_ratio -%}
                {% capture sizes %}(min-width: 750px) {{ settings.logo_width }}px, 50vw{% endcapture %}
                {% capture widths %}{{ settings.logo_width }}, {{ settings.logo_width | times: 1.5 | round }}, {{ settings.logo_width | times: 2 }}{% endcapture %}
                {{ settings.logo | image_url: width: 600 | image_tag:
                  class: 'header__heading-logo',
                  widths: widths,
                  height: logo_height,
                  width: settings.logo_width,
                  alt: logo_alt,
                  sizes: sizes,
                  preload: true
                }}
              </div>
            
            {%- else -%}
              <span class="h2">{{ shop.name }}</span>
            {%- endif -%}
          </a>
      {%- if request.page_type == 'index' -%}
        </h1>
      {%- endif -%}
    {%- endif -%}

    <div class="header__icons{% if section.settings.enable_country_selector or section.settings.enable_language_selector %} header__icons--localization header__localization{% endif %}">
      <div class="desktop-localization-wrapper">
        {%- if section.settings.enable_country_selector and localization.available_countries.size > 1 -%}
          <noscript class="small-hide medium-hide">
            {%- form 'localization', id: 'HeaderCountryMobileFormNoScript', class: 'localization-form' -%}
              <div class="localization-form__select">
                <h2 class="visually-hidden" id="HeaderCountryMobileLabelNoScript">{{ 'localization.country_label' | t }}</h2>
                <select class="localization-selector link" name="country_code" aria-labelledby="HeaderCountryMobileLabelNoScript">
                  {%- for country in localization.available_countries -%}
                    <option value="{{ country.iso_code }}" {%- if country.iso_code == localization.country.iso_code %} selected{% endif %}>
                      {{ country.name }} ({{ country.currency.iso_code }} {{ country.currency.symbol }})
                    </option>
                  {%- endfor -%}
                </select>
                {% render 'icon-caret' %}
              </div>
              <button class="button button--tertiary">{{ 'localization.update_country' | t }}</button>
            {%- endform -%}
          </noscript>

          <localization-form class="small-hide medium-hide no-js-hidden">
            {%- form 'localization', id: 'HeaderCountryForm', class: 'localization-form' -%}
              <div>
                <h2 class="visually-hidden" id="HeaderCountryLabel">{{ 'localization.country_label' | t }}</h2>
                {%- render 'country-localization', localPosition: 'HeaderCountry' -%}
              </div>
            {%- endform -%}
          </localization-form>
        {% endif %}

        {%- if section.settings.enable_language_selector and localization.available_languages.size > 1 -%}
          <noscript class="small-hide medium-hide">
            {%- form 'localization', id: 'HeaderLanguageMobileFormNoScript', class: 'localization-form' -%}
              <div class="localization-form__select">
                <h2 class="visually-hidden" id="HeaderLanguageMobileLabelNoScript">{{ 'localization.language_label' | t }}</h2>
                <select class="localization-selector link" name="locale_code" aria-labelledby="HeaderLanguageMobileLabelNoScript">
                  {%- for language in localization.available_languages -%}
                    <option value="{{ language.iso_code }}" lang="{{ language.iso_code }}" {%- if language.iso_code == localization.language.iso_code %} selected{% endif %}>
                      {{ language.endonym_name | capitalize }}
                    </option>
                  {%- endfor -%}
                </select>
                {% render 'icon-caret' %}
              </div>
              <button class="button button--tertiary">{{ 'localization.update_language' | t }}</button>
            {%- endform -%}
          </noscript>

          <localization-form class="small-hide medium-hide no-js-hidden">
            {%- form 'localization', id: 'HeaderLanguageForm', class: 'localization-form' -%}
              <div>
                <h2 class="visually-hidden" id="HeaderLanguageLabel">{{ 'localization.language_label' | t }}</h2>
                {%- render 'language-localization', localPosition: 'HeaderLanguage' -%}
              </div>
            {%- endform -%}
          </localization-form>
        {%- endif -%}
      </div>
      {% render 'header-search', input_id: 'Search-In-Modal' %}

      {%- if shop.customer_accounts_enabled -%}
        <a href="{%- if customer -%}{{ routes.account_url }}{%- else -%}{{ routes.account_login_url }}{%- endif -%}" class="header__icon header__icon--account link focus-inset{% if section.settings.menu != blank %} small-hide{% endif %}">
          {% render 'icon-account' %}
          <span class="visually-hidden">
            {%- liquid
              if customer
                echo 'customer.account_fallback' | t
              else
                echo 'customer.log_in' | t
              endif
            -%}
          </span>
        </a>
      {%- endif -%}

      {%- for block in section.blocks -%}
        {%- case block.type -%}
          {%- when '@app' -%}
            {% render block %}
        {%- endcase -%}
      {%- endfor -%}

      <a href="{{ routes.cart_url }}" class="header__icon header__icon--cart link focus-inset" id="cart-icon-bubble">
        {%- liquid
          if cart == empty
            render 'icon-cart-empty'
          else
            render 'icon-cart'
          endif
        -%}
        <span class="visually-hidden">{{ 'templates.cart.cart' | t }}</span>
        {%- if cart != empty -%}
          <div class="cart-count-bubble">
            {%- if cart.item_count < 100 -%}
              <span aria-hidden="true">{{ cart.item_count }}</span>
            {%- endif -%}
            <span class="visually-hidden">{{ 'sections.header.cart_count' | t: count: cart.item_count }}</span>
          </div>
        {%- endif -%}
      </a>
    </div>
  </header>

 

 

Also, what is the css selector for the header element according to the above code?

nileshthorath
Shopify Partner
1 0 0

Hi Anirudh,

I just saw your question and here my suggestion / simple steps for you to execute it, Use GSAP lib and Liquid code and all set.
And Yes I'm the one who developed your reference website bluorng.com & many more..

If you need more help, feel free to ping me on my IG @Dev.nileshrao


Happy to help,
Nilesh Thorath

UX UI Designer and Full Stack Developer with 15+ Years of Experience. I have developed 1000+ E-com store in my career span