Richard
Richard

Reputation: 1474

Anyway to use scrollTop but retain the hashtag?

I'm using the following code:

$('#toc a').on('click', function(e) {
          e.preventDefault();
          $link = $(this).attr('href');

          $('html, body').animate({
            scrollTop: $($link).offset().top - 10
          }, 1000 );
         
});

But would like it to keep the hashtag from the link in the web address. Is this possible with the code? Thanks

Upvotes: 0

Views: 197

Answers (1)

adeneo
adeneo

Reputation: 318212

$('#toc a').on('click', function(e) {
    $link = $(this).attr('href');

    $('html, body').animate({
        scrollTop: $($link).offset().top - 10
    }, 1000 );
});

Upvotes: 1

Related Questions