• Resolved lawmate

    (@lawmate)


    Hi

    I am using the Auberge theme and it seems to have a semi “sticky” menu, that stays at the top of the browser window as you scroll down the page. The problem is that it only seems to kick in after the user has scrolled down a portion of the page. I want the top menu header to stay at the top from the moment the page loads at the top all through the scroll down to the bottom of the page.

    I have tried editing the style.css by adding position:fixed; for various class names but I cannot get the whole of the header to do what I want. Changing the position attributes seems to rearrange the layout as well as fix it to the top of the page.

    I’ve tried a sticky menu plugin but that didn’t do anything. I’d rather edit the code if possible as I find the plugins more frustrating to work with.

    If anyone has any ideas, they’d be much appreciated!

    Many thanks

Viewing 4 replies - 1 through 4 (of 4 total)
  • Theme Author WebMan Design | Oliver Juhas

    (@webmandesign)

    Hi,

    I’m sorry but this is a design decision I’ve made when building the theme.

    To make the header sticky to top all the time you will need to modify the theme (via a child theme) or if you are not familiar with coding, consider hiring someone that can help. Please note that sticky header is a bit complex task to do it right and as you experienced, it can cause layout issues.

    To give you a tip, try to copy the assets/js/scripts-global.js file into your child theme (keeping the folder structure) and edit it there.

    Please note that I do not provide support for theme modifications: https://webmandesign.eu/manual/auberge/#child-theme

    Regards,

    Oliver

    Thread Starter lawmate

    (@lawmate)

    Hi

    Thanks for the reply. I will definitely play around with the code. I do quite a bit of C coding for electronics but very little web coding. I find the way that all the different code files interact with one another a little confusing, but I know it will only take some time to suss it out.

    I am already running a child theme so that’s OK. I will look into the scripts-global.js code and see if I can get something working. I’ll post the results here if anyone else want to change this.

    Thanks

    Thread Starter lawmate

    (@lawmate)

    OK, so I have it working to a state I’m happy with. It was pretty straight forward to be honest. The js code is nicely laid out and easy to read.

    For anyone else trying to do this, copy the scripts-global.js file with the same path to the child theme folder, as described above.

    When I opened up the file, there’s a clear contents that shows that the code dealing with the site header is in section 20. Once there, it is labelled as the sticky header.

    As I understand it, this is a function that is called when the scroll position is changed. When this happens, there are 2 variable loaded in, which are the current scroll position and the height of the header.

    Once loaded, there’s an if statement that checks to see if the scrolled position is more than 3 X the height of the header. If this is true then a call to remove a class called hide-sticky-header and add a class called sticky-header.

    After that there is an else if that checks whether the scroll position is above that 3 X the header height position and if so, remove the sticky-header class. I guess this is if the user scrolls up the page towards the top.

    There is another else that includes every other situation, which I guess is when the page is right at the top, in which case remove both the classes, as the header is in the position it needs to be anyway.

    What I wanted was just for the sticky-header to be true the whole time. To do this I simply commented out the first if condition, so change this line:
    if ( $documentScrollTop >= ( 1 * $headerHeight ) ) {
    to
    //if ( $documentScrollTop >= ( 1 * $headerHeight ) ) {

    then I also needed to comment out all the other conditions like this:

    
    /**
    } else if ( $documentScrollTop < ( 1 * $headerHeight ) && $documentScrollTop > ( 1 * $headerHeight ) ) {
    
    	$( 'body.sticky-header' )
    	.removeClass( 'sticky-header' )
    	.addClass( 'hide-sticky-header' );
    
    } else {
    
    	$( 'body' )
    	.removeClass( 'sticky-header hide-sticky-header' );
    
    }
    */
    

    At this point it sort of worked, but it seemed that adding the sticky-header class created an animated scroll down effect for the header that happened as soon as you started scrolling. This looks OK when you’re making the header sticky after it is out of the frame, but looks glitchy when you first start scrolling.

    To fix this, I changed when this function was called. Originally it happens when you scroll down the page and the code looked like this:
    .on( 'scroll', function() {
    but I changed it to
    .on( 'load', function() {
    and now it does it’s animated drop down thing when the page first loads and it looks OK.

    Thanks a lot for the theme Oliver and thanks for the pointer of how to make the changes, it was pretty straightforward to do.

    Theme Author WebMan Design | Oliver Juhas

    (@webmandesign)

    Hi,

    I’m glad you was able to solve this and thank you for sharing such a complete solution explanation! Great job!

    To give you some more tip, you can actually remove the header animation using this custom CSS:

    .sticky-header .site-header {
      animation: none;
    }
    

    Regards,

    Oliver

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Issues with “sticky” menu’ is closed to new replies.