Sticky Header not working on PC/Desktop

Solved

Sticky Header not working on PC/Desktop

nd23123
Tourist
9 0 0

The sticky header is enabled in our theme settings, it is working fine for mobile. 
But the PC/Desktop version is not working. (twigs.ae)

Accepted Solution (1)

oscprofessional
Shopify Partner
16115 2409 3121

This is an accepted solution.

Hello @nd23123 

Please navigate to your Online Store, go to Themes, select Edit Code, and add the following code to the theme.liquid file, placing it before the </body> tag:

 

<script>
$(window).on("scroll", function() {
makeHeaderSticky();
});

var $header = $("#HeaderWrapper");
var sticky = $header.offset().top;

function makeHeaderSticky() {
if ($(window).scrollTop() > sticky) {
$header.addClass("sticky");
} else {
$header.removeClass("sticky");
}
}
</script>
<style>
.header-wrapper.sticky {
width: 100%;
position: fixed;
top: 0;
left: 0;
z-index: 9999;
transition: all 0.3s ease-in-out;
}
</style>

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

View solution in original post

Replies 8 (8)

GTLOfficial
Shopify Partner
475 95 90

Hello @nd23123 
This seems to be working fine in my desktop.

- Buy me a Pizza
- If helpful then please Like and Accept Solution.
- Want to modify or custom changes or bug fix on the store Hire me. GTL web solutions
- Want Complete Storefront: Send an email ⇨- Email: info@gtlofficial.com - Skype: ritesh_27dh

Moeed
Shopify Partner
4991 1327 1610

Hey @nd23123 

 

Follow these Steps:

1) Go to Online Store
2) Edit Code
3) Find theme.liquid file

4) Add the following code in the bottom of the file above </body> tag

<style>
@media screen and (min-width: 768px) {
header#SiteHeader {
    position: fixed !important;
    width: 100% !important;
    margin-top: 28px !important;
}
.toolbar-section {
    position: fixed !important;
    width: 100% !important;
}
}
</style>

RESULT:

Moeed_0-1724313766423.png

 

If I managed to help you then, don't forget to Like it and Mark it as Solution!

 

Best Regards,
Moeed

-Need a Shopify Specialist? Chat on WhatsApp
- Custom Design | Advanced Coding | Store Modifications
- Your Coffee Tip and my code, A perfect blend. ❤️
nd23123
Tourist
9 0 0

Hi Moeed, this worked, but on our products page there is a space above the header

nd23123_0-1724325143747.jpeg

 

Moeed
Shopify Partner
4991 1327 1610

Hey @nd23123 

 

Try this code instead.

{% if template == 'index' %}
<style>
@media screen and (min-width: 768px) {
header#SiteHeader {
    position: fixed !important;
    width: 100% !important;
    margin-top: 28px !important;
}
.toolbar-section {
    position: fixed !important;
    width: 100% !important;
}
}
</style>
{% endif %}

 

If I managed to help you then, don't forget to Like it and Mark it as Solution!

 

Best Regards,
Moeed

-Need a Shopify Specialist? Chat on WhatsApp
- Custom Design | Advanced Coding | Store Modifications
- Your Coffee Tip and my code, A perfect blend. ❤️

steve_michael2
Excursionist
82 11 17

Hi @nd23123 , I hope you are doing well, 


1. Go to Online Store -> Theme -> Edit code.
2. Open your theme.liquid file
3. Paste the below code before </body> on theme.liquid

 

<style>
@media screen and (min-width: 768px) {
    header#SiteHeader {
       position: fixed !important;
       width: 100% !important;
       margin-top: 28px !important;
    }
   .toolbar-section {
       position: fixed !important;
       width: 100% !important;
   }
}
</style>

 

 

If my reply is helpful, kindly click like and mark it as an accepted solution.

Thanks!

Crafting exceptional online experiences with innovative design and technology.

Sweans
Shopify Partner
398 77 119

HI @nd23123 ,

 

Steps to Follow:

Go to Online Store:

 

In your Shopify admin, navigate to Online Store in the left-hand menu.

Edit Code:

 

Click on the Themes section.

Under the current theme, click on Actions > Edit Code.

Find theme.liquid File:

 

In the left sidebar, under the Layouts folder, find and click on theme.liquid.

Add the Code Above the </body> Tag:

 

Scroll down to the bottom of the theme.liquid file.

Add the following code just above the closing </body> tag:

 

<style>
header#SiteHeader {
    position: fixed !important;
    width: 100% !important;
}

.toolbar-section {
    position: fixed;
    width: 100%;
    z-index: 7;
}
</style>

 

I hope this helps! If it does, please like it and mark it as a solution! 

If you need further assistance, feel free to reach out!

 

Regards,

Sweans

- Was my reply helpful? Please Like and Accept the Solution or let me know by Buying me coffee!
- Want to modify or custom changes on store Hire me.
- Feel free to contact me at info@sweans.com regarding any help.
- To know more about me check out www.sweans.com

oscprofessional
Shopify Partner
16115 2409 3121

This is an accepted solution.

Hello @nd23123 

Please navigate to your Online Store, go to Themes, select Edit Code, and add the following code to the theme.liquid file, placing it before the </body> tag:

 

<script>
$(window).on("scroll", function() {
makeHeaderSticky();
});

var $header = $("#HeaderWrapper");
var sticky = $header.offset().top;

function makeHeaderSticky() {
if ($(window).scrollTop() > sticky) {
$header.addClass("sticky");
} else {
$header.removeClass("sticky");
}
}
</script>
<style>
.header-wrapper.sticky {
width: 100%;
position: fixed;
top: 0;
left: 0;
z-index: 9999;
transition: all 0.3s ease-in-out;
}
</style>

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
nd23123
Tourist
9 0 0

thanks for this, it works well now.