Forums

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

Home Forums JavaScript Problem with fixed header offsetting an html anchor

  • This topic is empty.
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #203443
    Robin
    Participant

    Hi All,

    I’m having an issue with fixed header offsetting an html anchor. Please check the below URL.

    http://codepen.io/rahuldsg/pen/ZGKmgy

    $('a[href*=#]:not([href=#])').click(function() {
    if (location.pathname.replace(/^//,'') == this.pathname.replace(/^//,'')
    || location.hostname == this.hostname) {
    var target = $(this.hash);
    target = target.length ? target : $('[name=' + this.hash.slice(1) +']');
    if (target.length) {
    $('html,body').animate({
    scrollTop: target.offset().top
    }, 1000);
    return false;
    }
    }
    });

    #203451
    Paulie_D
    Member

    Could you clarify exactly what the issue is.

    Personally, I’d just grab the height of the header and offset by that much.

    http://codepen.io/Paulie-D/pen/MwmZZX/

    #203479
    Shikkediel
    Participant

    And if it’s about the top anchor, you could add some padding or margin (with the same height as the header). Looks like that was done in the above example as well.

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