Ways to ensure that Jquery events execute only the most recent one triggered

Recently, I created a navigation bar that works quite well. However, there is a slight issue - a small rectangle appears below the navigation tabs and moves under the tab that the user hovers over. The problem arises when the bar moves under every tab that has been hovered over, rather than just staying under the one currently being hovered over or the most recently hovered over. If this explanation is unclear, please check out the complete code to better understand the issue. Thank you for your attention.

<div id='backNav'>
    <div id='navBar'>
      <div id='navLoc'></div>
    </div>
    <div id='cont'>
      <ul id='navList'>
        <li id='home' class='navItem'>Home</li>
        <li id='about' class='navItem'>About</li>
        <li id='shop' class='navItem'>Shop</li>
        <li id='blog' class='navItem'>Blog</li>
      </ul>
    </div>
  </div>

var main = function() {
  var navLoc = $('#navLoc');

  $('#home').hover(function(){
    navLoc.animate({
      left:75
    },300 )
  });

  $('#about').hover(function(){
    navLoc.animate({
      left:243
    },300 )
  });

  $('#shop').hover(function(){
    navLoc.animate({
      left:415
    },300 )
  });

  $('#blog').hover(function(){
    navLoc.animate({
      left:575
    },300 )
  });
}

$(document).ready(main);


Full Code: https://jsfiddle.net/tjqLbne1/
(Please note that the bar may not align perfectly with the tabs in the fiddle due to window size constraints, but the overall idea is still conveyed)

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

How to replace text between two HTML tags with white space using PHP

I'm attempting to create a script that will replace all characters between two specific HTML tags (<del> tags) with a space, but I am encountering difficulties with the PHP string functions. For example, given the initial string "blahblah<d ...

Instructions for deleting a class from the body with jQuery while incorporating AngularJS

When using jQuery $(document).ready(function() { $("#pid1").removeClass("login_page"); }); HTML <body class="login_page" id="pid1" ng-app="myApp" ng-controller="myCtrl"> On the main page, a class is removed, but on the login page I want to ...

Fixed position scrollable tabs with Material UI

I recently implemented material-ui scrollable tabs in my project, referencing the documentation at https://mui.com/material-ui/react-tabs/#scrollable-tabs. Here is a snippet of the code I used: <Tabs value={value} onChange={handleChange ...

CSS and HTML made easy: How come my page is displaying unpredictable outcomes?

Something seems off with this page when it loads. It only displays correctly after resizing the browser window. Random combinations appear before the resize, which is quite strange. Can anyone identify what's causing this issue? Here's the JS f ...

ng serve issue persists even after resolving vulnerabilities

Can anyone assist me in resolving why I am unable to start my project after fixing 3 high vulnerabilities? I ran npm audit to identify the vulnerabilities and then used npm install --save-dev @angular/<a href="/cdn-cgi/l/email-protection" class="__cf_em ...

Accessing 'this' within a Firebase callback function

As I work on my Vue.js application, I encounter an issue with fetching data from Firebase when the component mounts. While I am able to successfully retrieve the data, I am struggling to write it into a Vue.js data property. I have tried using this.propert ...

trouble combining two arrays of JavaScript objects

I'm facing a challenge with an object array. I need to add a new object "WITH" a specific index, but I'm unsure of the correct approach. This is my current attempt: //ORIGINAL DATA: this.fetchedData = [{ "startMinute": 0, //Remove "annotati ...

Angular Directive: The power of one-way binding

Is there a simple way to implement one-way binding in an angular directive? I've been searching for an easy example, but haven't had much luck. The documentation isn't very clear either: & or &attr - allows you to execute an expre ...

Server connectivity issues due to air disruptions

Our team has developed an innovative Air application for delivering course material to our clients. However, we have encountered a connectivity issue with some clients that we were able to replicate. To provide some context, the application utilizes jQuer ...

All browsers experiencing issues with autoplay audio function

While creating an HTML page, I decided to include an audio element in the header using the code below: <audio id="audio_play"> <source src="voice/Story 2_A.m4a" type="audio/ogg" /> </audio> <img class= ...

Expand an image to its full dimensions when it is initially loaded

Currently, I am experimenting with placing images of bubbles randomly on a webpage. To create the illusion of the bubble expanding in size from nothing to its full scale, I have been using CSS and specifically the transform:scale(); property. However, my ...

What is the process for implementing document.ondrop with Firefox?

I'm experiencing an issue where the document.ondrop function seems to be working in Chrome, but not in Firefox. Here's a link to an example demonstrating the problem: In the example, if you try to drop a file onto the page, it should trigger an ...

Altering the JavaScript variable by selecting an option from a dropdown list

After downloading a choropleth map from leafletjs.com, I encountered an issue with multiple JS files labeled by year (e.g. us-states2012.js, us-states2013.js). The challenge now is to implement a drop down menu in such a way that selecting a specific year ...

Understanding HTML through regular expressions

Can anyone assist me in finding the regular expressions needed to parse an HTML file for a program I'm working on? Here are some specific ones I'm looking for: <div> <div class=”menuItem”> <span> class=”emph” Any str ...

Transferring retrieved information from one division to another

This snippet of code demonstrates the process of fetching names from a MySQL database using PHP and Ajax. Updated Code index.php <html> <head> <script language="javascript"> function showresult( ...

Retrieving Data with AngularJS: Making HTTP Calls and Handling Responses

I seem to be facing a bit of a hurdle in executing an HTTP GET request and retrieving the data properly in JavaScript. The goal is to attach this data to the global window variable, but I'm encountering some difficulty. Here is the code snippet for t ...

Creating a child div that expands to the same size as its parent div using CSS only

I am looking to create two div elements with 100% height. The parent div should display an image and adjust its size automatically. The child div should act as a color filter and maintain the same size as the parent div even when the page is resized. I ...

The AngularJS Controller Function

I'm working with a code snippet that includes an Angular Modular Controller containing a function inside the controller itself with a call. I'm unsure if this coding practice is allowed in JavaScript or Angular, and if it is, how does it work? Ta ...

Error in TypeScript: Trying to set property 'test' on an undefined object

Trying to grasp TypeScript concepts, but struggling with a misunderstood notion... Encountering this Error: TypeError: Cannot set property 'test' of undefined at testResponse (/home/mcfly/bimbim/geoloc_API/dist/routes/geoRouter.js:11:19) a ...

Extracting the content attribute from this code using BeautifulSoup: How can I achieve this?

I am struggling to extract the "content" attribute from the following HTML code: <meta name="description" content="Definition: What is a leadership performer?"/> My aim is to scrape "Definition: What is a leadership performer?" f ...