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
11693 2292 2472

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 & Accept solution!
- Ryviu - Product Reviews & QA app: Import reviews from AliExpress, Amazon, Etsy, Walmart, Dhgate and CSV.
- Amazon Products Importer - Import Amazon Products to Dropship in Your Store!
- Lookfy Gallery: Lookbook Image - Gain customers with photo gallery, video & shoppable image
- Reelfy‑Shoppable Videos+Reels: Create shoppable videos to engage customers and drive more sales.
- En...
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
11693 2292 2472

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 & Accept solution!
- Ryviu - Product Reviews & QA app: Import reviews from AliExpress, Amazon, Etsy, Walmart, Dhgate and CSV.
- Amazon Products Importer - Import Amazon Products to Dropship in Your Store!
- Lookfy Gallery: Lookbook Image - Gain customers with photo gallery, video & shoppable image
- Reelfy‑Shoppable Videos+Reels: Create shoppable videos to engage customers and drive more sales.
- En...
Sign up now.