• if(window.location.hash) {
    $(‘html, body’).animate({
    scrollTop: $(window.location.hash).offset().top – 82
    }, 1000 );
    }

    The following block is responsible for the smooth scroll on load and does it well. However it doesn’t take account of false html-node ids. Which would lead to an exception here: $(window.location.hash).offset() since $(window.location.hash) would return [undefined].

    My fix since (the previous version) would be to wrap a try/catch around the block.
    if(window.location.hash) try {
    $(‘html, body’).animate({
    scrollTop: $(window.location.hash).offset().top – 82
    }, 1000 );
    }catch(e){}

    Greetings Patrick M.

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Problem: Scrollto hash on load if id does not exist’ is closed to new replies.