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

Injecting JSON response data into HTML using jQuery

How can JSON return data be properly appended into an img src tag? HTML <a class="bigImg rght" style="width:258px;"> <img src="" alt="Slide" width="298" height="224" /></a> Using Ajax to Update Image Source: var parent_img = $(t ...

The $resources headers have not been updated

My objective is to include a header with each HTTP request for an ngResource (specifically, an auth token). This solution somewhat accomplishes that: app.factory('User', ['$resource','$window', function($resource,$window,l ...

The child_process in Node is attempting to utilize /usr/bin/zsh, but unfortunately, it is unable to do so because

Recently, I've been encountering issues with several npm commands failing, accompanied by an error message that looks like this: npm ERR! code ELIFECYCLE npm ERR! syscall spawn /usr/bin/zsh npm ERR! file /usr/bin/zsh npm ERR! path /usr/bin/zsh npm ER ...

Keep table header stationary while accommodating varying column widths

I have come across various solutions for freezing a table header row, such as creating a separate table containing only the header and hiding the header of the main table. However, these solutions are limited to cases where column widths are predetermine ...

What does the `Class<Component>` represent in JavaScript?

Apologies for the lackluster title (I struggled to think of a better one). I'm currently analyzing some Vue code, and I stumbled upon this: export function initMixin (Vue: Class<Component>) { // ... } What exactly does Class<Component> ...

Can you provide a way to directly calculate the total length of all arrays within an array of objects?

How can I find the total length of arrays in an array of objects based on a specific property? var myArray = [{ "a" : 1, "b" : another Array }, { "c" : 2, "b" : another Array } ..... ] Is there a more efficient way to achieve this instea ...

The payload transmitted from JavaScript to Django Views is devoid of any content

I'm currently working on sending data from JavaScript to Django using ajax. Below is the code snippet I am using for this: var json_name = {'name': 123} $.ajax({ method: 'POST', url: ...

Explore various locations and conceal different divs by clicking

Can someone help me figure out how to hide the placeholders when the focus changes in a form? Here is the code snippet that illustrates my problem. Your assistance is greatly appreciated, João var inputs = Array.prototype.slice.call(document.querySele ...

Show the current temperature data retrieved from the weather API

I'm trying to figure out what's causing the issue with the temperature not displaying. Can anyone help me identify and fix the error? <script type="text/javascript"> $.ajax({ url: 'https://api.weather.gov/gridpoints/EWX ...

React and Rails are not playing nice when it comes to AJAX POST requests - all

I'm currently facing an issue while setting up this AJAX POST request in my react component to interact with my rails api controller. The browser console shows a 404 error and I am unable to trigger the pry debugger. react/src/pages/HomeIndex.js ge ...

SignalR gets stuck on the 'Initiating start request' screen, halting all progress

SignalR has been causing some strange behavior for me lately. After doing some refactoring, I started experiencing connectivity issues. It seems like my code was just lucky to work before because it didn't follow the recommended practices. For example ...

In the following command, where is the PORT stored: ~PORT=8080 npm App.js?

section: Let's consider the following code snippet located in the App.js file: console.log(`This is the port ${process.env.PORT}`); Is there a method to retrieve the value of PORT from outside the running process? ...

Attaching a function to the "onselect" event that manages the character limit within an input text field

I have been developing a function to restrict the number of characters a user can enter into a text field. Here's what I have so far: $.fn.restringLength = function (id, maxLen) { $(id).keypress(function(e){ var kCode = ...

On the same line, there are two divs with different characteristics - one dynamically changing width and the

I am facing an issue with arranging two divs under one parent div. The parent div is set to have a width of 100%: <div id="parent"> <div class="left"></div> <div class="right"></div> </div> The specific conditions ...

Determining the specific button pressed using jQuery

There are two buttons present: <input type="button" name="hideAll" value="Hide Descriptions"/> <input type="button" name="showAll" value="Show Descriptions"/> Can someone guide me on how to determine which button has been clicked using jQuery ...

Utilizing Jquery on the client side in conjunction with a Node.js server

I am using nodejs within a docker-compose container to create a local web app. My goal is to use jquery on the client-side to load an HTML file into a div, but I'm encountering issues with it not working properly. Both the initial index.html and the n ...

CSS tip: Display only the latest x entries on a list

Can CSS be used to display only the most recent x items in a list? The code below reveals every item except the first two. How can I make it so that only the last two items are displayed in the list? ul li { display: none !important; } ul li:nth-las ...

Express is unable to locate the specified property

Here is my controller code snippet: exports.showit = function(req, res){ res.render('showpost', { title: req.post.title, post: req.post }) } In my post model, I have included title and name objects: title: {type : String, default : &apos ...

Transmitting content via ajax to a dropdown list does not always ensure that the selection is fully set

Using AJAX, I am sending an ID to retrieve a specific name (label) along with its code. This retrieved data will be displayed as the selected value in my dropdown list within a Bootstrap Modal Form. Currently, I am able to fetch the code enclosed within t ...

`The ultimate guide to fixing the node.js ENOENT error`

Currently, I am utilizing express.js to execute this code snippet: var repl = require("repl"); var express = require('express'); var app = express(); var server = require('http').createServer(app); var io = require('socket.io&apos ...