Shopify themes, liquid, logos, and UX
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!
@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:
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.
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.
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:
<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:
/* 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.
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?
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
By investing 30 minutes of your time, you can unlock the potential for increased sales,...
By Jacqui Sep 11, 2024We appreciate the diverse ways you participate in and engage with the Shopify Communi...
By JasonH Sep 9, 2024Thanks to everyone who participated in our AMA with 2H Media: Marketing Your Shopify St...
By Jacqui Sep 6, 2024