I am using Minimal theme and the code above did not seem to work properly for me, although I do see that it works well on the sample site provided. So take that as you will. I also prefer the slight drop shadow that Sean’s original code gives to the header, so I wanted to find a way to make the original code work with my theme.
Here is a solution I came up for Sean’s / Shopify’s sticky header code that works on my site. I’m not a professional developer, so buyer beware.
- In the theme.js code, replace
$('#PageContainer').css('padding-top', $headerHeight);
with
$('.main-content').css('padding-top', $headerHeight);
- In timber.scss.liquid, locate
.main-content {
display: block;
margin-top: $gutter * 2;
padding-bottom: $gutter * 2;
}
and add a line for padding-top with some hard-coded placeholder pixels
.main-content {
display: block;
margin-top: $gutter * 2;
padding-bottom: $gutter * 2;
**padding-top: 180px;**
}
Mess around with the “180px” number to find a padding that works for your site/header. This is just a placeholder to make sure the content loads immediately some place below the header before the javascript has a chance to kick in and calculate the actual padding required by your specific header. Before I added this second step, the site would immediately load with content behind the header and then after a second or two the content would be pushed down to the correct position. By making both these changes, the content will load in a way that is not disruptive to the user. I’m assuming it’s not good to have such a hard-coded pixel value for padding-top, so this is a hybrid solution that holds the page content in roughly the right place while javascript comes up behind and changes it into a more precise number in the spirit of adaptivity.
Again, I’m not a professional developer and maybe a professional developer can offer some advice or improvements. But so far this is working well for me on both desktop and mobile.