The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript Sticky nav jumping sometimes in webkit browsers

  • This topic is empty.
Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
  • #40338

    I have a strange problem which I cannot get my head around, I have created a sticky nav via jquery which works fine in all browsers but Chrome and Safari, sometimes it works and sometimes it doesn’t if you refresh the page. Most of the time the menu jumps to the top of the page as soon as you start browsing. You can view the problem here:

    The jQuery concerned is:

    var yOffset = $(“#local-nav-wrapper”).offset().top;
    $(window).scroll(function() {
    if ($(window).scrollTop() > yOffset) {
    ‘top’: ‘0’,
    ‘bottom’: ‘auto’,
    ‘position’: ‘fixed’,
    } else {
    ‘top’: ‘auto’,
    ‘bottom’: ‘0’,
    ‘position’: ‘absolute’,

    Any help would be greatly appreciated.


    I see the problem is that yOffset is not always getting the correct value, not sure why this happens. Try changing this
    var yOffset = $(“#local-nav-wrapper”).offset().top;

    into this
    var yOffset = $(“#local-nav-wrapper”).position().top;


    var yOffset = 444;

    this isn’t that flexible, but I see you have a fixed height there


    var yOffset = $(“#local-nav-wrapper”).position().top; seems to make it a bit more reliable in webkit, but the menu still jumps a bit before it’s supposed to. I can’t give a set offset like 444 as the layout is responsive.



    In fact it still causes the original problem when I upload it to the server, it appears to be more reliable on localhost. I can’t get my head around this. Everything is the same between localhost and my server?


    sounds like a timing problem. When it loads in localhost it’s really fast anad it gets the correct value, but on the server it gets the value before the elements are set.
    you could move the function from $(document).ready to $(window).load but that would make a strange jumping effect on the menu if a user starts scrolling immediately after the page shows up. Anyway I think it’s worth giving it a try

Viewing 6 posts - 1 through 6 (of 6 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.