Shopify themes, liquid, logos, and UX
Hello!
I have the sticky header option active in my website but I want to hide the header while I'm scrolling down (both on mobile and desktop). This way, if I scroll down the header will hide and when I scroll up it will appear again.
Just like the nike website: www.nike.com
Ideally it should have a smooth animation rather than an instant hiding/appearing.
My theme is Stiletto and my website is: https://kv4bbbag5hlpi4gm-60150284501.shopifypreview.com
I would really appreciate some help folks!
Solved! Go to the solution
This is an accepted solution.
Hi @martujv
Please add this code to your theme.liquid file, before </body> tag in Online Store > Themes > Edit code
<script>
document.addEventListener('DOMContentLoaded', () => {
const header = document.querySelector('.header__outer-wrapper'); // Adjust selector if needed
let lastScrollY = window.scrollY;
window.addEventListener('scroll', () => {
const currentScrollY = window.scrollY;
if (currentScrollY < lastScrollY) {
// Scrolling up
header.classList.add('scrolled-up');
} else {
// Scrolling down
header.classList.remove('scrolled-up');
}
lastScrollY = currentScrollY;
});
});
</script>
<style>
html.sticky-header-enabled .shopify-section.header__outer-wrapper {
position: relative !important;
}
html.sticky-header-enabled .shopify-section.header__outer-wrapper.scrolled-up {
position: sticky !important;
}
</style>
- Solved it? Hit Like and Accept solution! ❤️Buy Me Coffee❤️
- Reton: Loyalty & Rewards - Earn points through tasks, redeem for discounts, and enjoy exclusive VIP rewards!
- Ryviu - Reviews & QA app: Collect product reviews, import reviews from AliExpress, Amazon, Etsy, Walmart, Shopee, Dhgate and CSV.
- Lookfy Gallery: Lookbook Image: Easy and fast to create Photo Gallery, Lookbook, Shop The Look.
- Reelfy‑Shoppable Videos+Reels: Create shoppable videos to engage customers and drive more sales.
- Enjoy 1 month of Shopify for $1. Sign up now.
This is an accepted solution.
Hi @martujv
Please add this code to your theme.liquid file, before </body> tag in Online Store > Themes > Edit code
<script>
document.addEventListener('DOMContentLoaded', () => {
const header = document.querySelector('.header__outer-wrapper'); // Adjust selector if needed
let lastScrollY = window.scrollY;
window.addEventListener('scroll', () => {
const currentScrollY = window.scrollY;
if (currentScrollY < lastScrollY) {
// Scrolling up
header.classList.add('scrolled-up');
} else {
// Scrolling down
header.classList.remove('scrolled-up');
}
lastScrollY = currentScrollY;
});
});
</script>
<style>
html.sticky-header-enabled .shopify-section.header__outer-wrapper {
position: relative !important;
}
html.sticky-header-enabled .shopify-section.header__outer-wrapper.scrolled-up {
position: sticky !important;
}
</style>
- Solved it? Hit Like and Accept solution! ❤️Buy Me Coffee❤️
- Reton: Loyalty & Rewards - Earn points through tasks, redeem for discounts, and enjoy exclusive VIP rewards!
- Ryviu - Reviews & QA app: Collect product reviews, import reviews from AliExpress, Amazon, Etsy, Walmart, Shopee, Dhgate and CSV.
- Lookfy Gallery: Lookbook Image: Easy and fast to create Photo Gallery, Lookbook, Shop The Look.
- Reelfy‑Shoppable Videos+Reels: Create shoppable videos to engage customers and drive more sales.
- Enjoy 1 month of Shopify for $1. Sign up now.
Hello, Dan! You can't imagine how glad I am for your help. It works and it's just like I wanted it to be! Thank you very much.
Just one thing, is there any way to add some sort of smooth 0.5s animation (an animation of the header coming down and up, depending if you scroll down or up), rather than it being an instant appearing / disappearing?
Thank you again!
Hey Community! As we jump into 2025, we want to give a big shout-out to all of you wh...
By JasonH Jan 7, 2025Hey Community! As the holiday season unfolds, we want to extend heartfelt thanks to a...
By JasonH Dec 6, 2024Dropshipping, a high-growth, $226 billion-dollar industry, remains a highly dynamic bus...
By JasonH Nov 27, 2024