What's your biggest current challenge? Have your say in Community Polls along the right column.

How to make header sticky when scrolling up on bullet theme

Solved

How to make header sticky when scrolling up on bullet theme

SF007
Shopify Partner
2 0 0

I am using bullet theme. There is only one option for header sticky. It sticks all the time. I need to make it sticky only scrolls up. When scrolling down, it needs to be hidden. How to do that?

I tried this js code, but not working

 

 

 

// Hide header on scroll down
var didScroll;
var lastScrollTop = 0;
var delta = 5;
var navbarHeight = $('header').outerHeight();

$(window).scroll(function(event){
    didScroll = true;
});

setInterval(function() {
    if (didScroll) {
        hasScrolled();
        didScroll = false;
    }
}, 250);

function hasScrolled() {
    var st = $(this).scrollTop();
    
    // Make scroll more than delta
    if(Math.abs(lastScrollTop - st) <= delta)
        return;
    
    // If scrolled down and past the navbar, add class .nav-up.
    if (st > lastScrollTop && st > navbarHeight){
        // Scroll Down
        $('header').removeClass('site-header').addClass('nav-up');
    } else {
        // Scroll Up
        if(st + $(window).height() < $(document).height()) {
            $('header').removeClass('nav-up').addClass('site-header');
        }
    }
  
    lastScrollTop = st;
}

 

 

Accepted Solution (1)

Dan-From-Ryviu
Shopify Partner
10275 2040 2111

This is an accepted solution.

Hi @SF007 

Please try to add this CSS code to theme.liquid file and check again 

<style>
header.site-header {
position: sticky;
top: 0px;
}
</style>

Make sure you disable the option 'Enable sticky header' in Online store > Themes > Customize > Header

Screenshot 2024-11-11 at 14.14.39.png

- Helpful? Like and Accept solution! Or Support me: Buy Coffees
- 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.

View solution in original post

Replies 2 (2)

George011
Visitor
3 0 0

 

Make sure your header has a fixed or sticky positioning to enable smooth hiding and revealing.

Like this:
header {

position: fixed;

width: 100%;

top: 0;

transition: transform 0.3s ease;

}

I got my header sticky here with this code, you should try it as well.

 

Dan-From-Ryviu
Shopify Partner
10275 2040 2111

This is an accepted solution.

Hi @SF007 

Please try to add this CSS code to theme.liquid file and check again 

<style>
header.site-header {
position: sticky;
top: 0px;
}
</style>

Make sure you disable the option 'Enable sticky header' in Online store > Themes > Customize > Header

Screenshot 2024-11-11 at 14.14.39.png

- Helpful? Like and Accept solution! Or Support me: Buy Coffees
- 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.