skip to Main Content
<div class='title' id='about'>About Us</div>

<a class='mm' href='about.php#about'>About Us</a>

I have a sticky positioned element above the target div so the .title div is not visible after loading the page

How can I scroll up the document after loading, for example for 54px, so the target div comes into view?

I tried this, without success:

$(window).on('load', function(){
    if(!window.location.hash == ''){
        window.scrollBy({top: 54, behavior: 'auto'});
    }
});

2

Answers


  1. If a sticky header gets in the way of the scrolled-to Target element, use in CSS:

    /* body or your scrollable wrapper */
    scroll-margin-top: 54px;
    

    given your sticky page nav or header occupies that 54px height.

    Login or Signup to reply.
  2. on page reload, cant you just re-direct page to href=about.php#about

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search