Dropping anchor whilst skipping or jumping

One of my website elements is a drop anchor that connects from a downwards arrow situated at the bottom of a full-page parallax image to another section on the same page. The HTML code snippet for the drop anchor is as follows:

<section id="first" class="big-image parallax lander" style="background-image: url(&quot;https://wagstaffsandbx.wpengine.com/wp-content/uploads/2017/06/Homepage-Photo-1.jpg&quot;); background-position: 50% -7.2px;" data-stellar-background-ratio="0.2" data-stellar-vertical-offset="50">

    <a href="#welcome" class="arrow"><img class="down-arrow" src="https://wagstaffsandbx.wpengine.com/wp-content/uploads/2017/06/down-arrow.png" alt="down-arrow"></a>

</section>

The destination of this drop anchor is defined in the following HTML code snippet:

<section id="welcome" class="text-block"><h1>welcome</h1><p>Pitchfork mumblecore stumptown, intelligentsia wolf put a bird on it man bun wayfarers organic actually sartorial. Sriracha disrupt kickstarter fingerstache selvage pour-over. Paleo ugh lumbersexual, kinfolk banjo banh mi meditation cliche 3 wolf moon single-origin coffee viral blog polaroid pop-up.</p>
</section>

Although clicking on the arrow triggers the smooth scroll to the drop anchor location, there seems to be an issue where the scroll jumps downward unnecessarily after reaching the destination. I have included the jQuery script responsible for the smooth scrolling below. Note that there is a specified offset of 140px for navigation:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
  // Add smooth scrolling to all links
  $("a.arrow").on('click', function(event) {

    if (this.hash !== "") {
      event.preventDefault();
      var hash = this.hash;

      $('html, body').animate({
        scrollTop: $(hash).offset().top -140
      }, 800, function(){
        window.location.hash = hash;
      });
    } // End if
  });
});
</script>

To witness the issue firsthand, you can visit the following link:

To access the site demo, use UN: demo and PW: password when prompted.

Any thoughts or suggestions on how to resolve this issue?

Answer №1

The issue at hand is directly tied to the following code snippet:

    // Add hash (#) to URL when done scrolling (default click behavior)
    window.location.hash = hash;

Modifying the location in this manner prompts a specific response from the browser.

Consider substituting it with the subsequent code block:

if (typeof (history.pushState) !== 'undefined') {
    var obj = {title: $('head title').text(), URL: hash};
    history.pushState(obj, obj.title, obj.URL);
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Leveraging nodemailer and handlebars for personalized email templates

I'm encountering an issue and struggling to pinpoint what exactly is causing it. Whenever I execute my code, the following error message pops up: [Error: ENOENT: no such file or directory, open 'C:\Users\Alex\Desktop\emailtes ...

Switching between table rows - managing open rows efficiently

Currently, I am working on an extensive database project involving pulling a large amount of data from a database. My focus is on displaying basic information in one visible row while concealing more detailed information in another row. By clicking the &ap ...

Steer clear of using grey backgrounds for anchors/links in IE 10

What is the best way to prevent the irritating grey background that appears on anchors in IE 10 when they are clicked? ...

Effortless glide while dragging sliders with JavaScript

In the code below, an Object is looped through to display the object key in HTML as a sliding bar. jQuery(function($) { $('#threshold').change(updateThreshold); function updateThreshold () { var thresholdIndex = parseInt($(&apos ...

Implementing a vertical tabindex change in Material UI Dialogue table

My material UI dialogue contains a table: <Dialog open={open} onClose={handleClose} maxWidth={'xl'} aria-labelledby='scroll-dialog-title' aria-describedby='scroll-dialog-description' disa ...

Determine the number of days without including weekends and holidays using JavaScript

I am working on a code that calculates the total number of days excluding weekends and specified holidays. After researching on various platforms like stackoverflow and adobe forum, I have come up with the following code. If a public holiday falls on a w ...

Is it true that Javascript does not allow for saving or outputting actions?

After coming across this question, I discovered a way to extract a specific element from a Google translate page using Javascript. However, I also learned that it is nearly impossible to directly save something to the clipboard in Javascript without user i ...

Enhance Your Website with HTML and JavaScript

Here is the code snippet I am working with: sTAT **javascript** var acc = document.getElementsByClassName("item-wrapper"); var i; for (i = 0; i < acc.length; i++) { acc[i].onclick = function(){ this.classList.toggle("selected"); this.nextElementS ...

Redirecting script upon successful connection detection

I have created a script that checks for internet connectivity using an image, and redirects if internet is available. However, the issue is that it caches the images, leading to attempts to load them even when offline. Is there a different approach I can ...

Elusive Appearance of the Flask Flash Message

I have developed a web application using Flask that allows users to upload files to an S3 storage. However, I would like to enhance the user experience by showing them the progress of their file uploads in real-time. To achieve this, I am utilizing Flash t ...

Error: jQuery is unable to access the property 'xxx' because it is undefined

While attempting to make a post request from the site to the server with user input data, I encountered an error message saying TypeError: Cannot read property 'vehicle' of undefined as the response. Here is the HTML and script data: <!DOCTY ...

Is there a way to split each foreach value into distinct variables?

I am looking to assign different variables to foreach values. I have fetched data from an API in JSON format, and then echoed those values using a foreach loop. My goal is to display the echoed value in an input box using JavaScript. I attempted the follow ...

Track and manage date ranges inclusive of specific times

http://jsfiddle.net/7vzapm49/1/ var startdatearr = [new Date("04 Dec 2014 14:30:00").toUTCString(), new Date("07 Dec 2014 14:30:00").toUTCString()]; var enddatearr = [new Date("05 Dec 2014 14:30:00").toUTCString(), new Date("08 Dec 2014 14:30:00").toUTCSt ...

How can I design a tooltip window using HTML, jQuery, or other elements to create a box-like effect?

As someone who is new to front end development, I am facing a challenge with my web app. The requirement is that when a user hovers over an image, I need a 'box' to open nearby and display a pie chart. Although I have managed to get the hover fu ...

What is the most creative way you can think of to create a CSS/JS animated

Is using an animated SVG the best way to create these wavy blobs for mobile compatibility? What approach would you take? Here is a similar example I found var wave = document.createElement("div"); wave.className += " wave"; docFrag.appendChil ...

Setting a cookie in a browser using an AJAX response: A step-by-step guide

When utilizing a Javascript function with jQuery to send a POST request to a web service, the response from the web server includes a header "Set-Cookie: name=value; domain=api.mydomain.com; path=/", along with a JSON body. However, despite this expected ...

Cease the use of bi-directional data binding on an Angular directive

One way I've been attempting to send information to a directive is through the following setup: <ui-message data="{{app}}"></ui-message> In my controller, this is how I define it: app.controller("testCtrl", function($scope) { $scope.a ...

Tips for dealing with event bubbling in React

Looking for a way to add an onBlur event to the left panel so that it closes when the user clicks on the right panel. I attempted using onMouseLeave but the closing animation isn't as smooth as desired. Additionally, I'd like for users to close t ...

Uploading information from a confirmation page to the controller

Within this cshtml file, I have included a model. This specific page serves as a confirmation page where the user is able to review and verify that all entered information is correct before proceeding. There is a link button (not part of the displayed cod ...

Using nightwatch.js to verify elements across different parts of a webpage

Currently engaged in working with nightwatch.js and encountering an issue with a particular page file structure: sections: { table: { selector: '.sr-filterable-data-layout--collection', elements: { header: { ...