0

The issue I am having:

Within my nav bar on my site I have a hamburger menu that contains 2 items:

  1. Contact
  2. Testimonials

From my hamburger menu drop down, I select the anchor tag labeled Testimonials.

Jquery applies a smooth scroll top to the anchor element and a hash will be placed to end of the URL like below:

https://example.com/#123456

Here is the code I currently have:

$(document).on("click",'.super-navbar__actions', function() {
    var testimonialsLink = $('.super-navbar__menu-item-list a:nth-child(2)');
        
    $(testimonialsLink).attr('href',"#block-9d888965d45244f4a0ebb3d7ded725bc");
       
    $(testimonialsLink).removeAttr("target");
        
    $('a[href^="#"]').on('click', function (e) {
       e.preventDefault();
    
       var targetEle = this.hash;
       var $targetEle = $(targetEle);
  
        $('html, body').stop().animate({
          'scrollTop': $targetEle.offset().top-100
           }, 800, 'swing', function () {
             window.location.hash = targetEle;
             });
        });
        
 });
 

Goals:

  1. I'd like to have the ability to refresh the page and start at the top of the existing page as if I had never selected the anchor link from the hamburger menu.(Currently upon reload the page will begin at the last anchor position which is halfway down the page which i not he best experience)

  2. I'd like the ability to navigate back to the home page without the browser automatically anchoring me to the previously selected anchor position.

  3. Lastly, within the navbar hamburger selection Testimonials, I'd like to be able to navigate to the testimonials section from other pages.

I am totally stuck with this one and have looked high and low to find an elegant solution with Jquery.

I have tried:

How to disable anchor "jump" when loading a page? append /remove anchor name from current url without refresh Attempting to remove anchor tags from the URL Remove anchor link after scrolling - works also on links from another page

How to refresh a page and load at top after an anchor has been clicked, ignoring the anchor, and resetting back to the top?

With no luck :/

ratsuns
  • 23
  • 4

0 Answers0