Using jQuery, it is possible to return animated content to its original position after hovering

I have a horizontal menu and I am looking to implement an effect where it moves 20px left when hovered over and returns to its original position when the mouse is no longer hovering over it. I would like to achieve this using JQuery. Can anyone assist me with this? Here is the code that I currently have:

JQuery:

 $(document).ready(function () {
     $("div.menu li").OnMousehover(function () {
         $("li").animate({ left: '20px' });
     });
 });

ASP.NET:

<div>
<asp:Menu ID="Menu" runat="server" CssClass="menu" EnableViewState="false" IncludeStyleBlock="false" Orientation="Horizontal">
  <Items>
    <asp:MenuItem NavigateUrl="~/Page1.aspx" Text="Page1" />
    <asp:MenuItem NavigateUrl="~/Page2.aspx" Text="Page2" />
    <asp:MenuItem NavigateUrl="~/Page3.aspx" Text="Page3" />
    <asp:MenuItem NavigateUrl="~/Page4.aspx" Text="Page4" />
    <asp:MenuItem NavigateUrl="~/Page5.aspx" Text="Page5" />
  </Items>
</asp:Menu>
</div>

Answer №1

.hover() is the solution you need.

$(document).ready(function (){
     $("ul.menu li").hover(
         function() {
             $(this).animate({ left: '-20px' });
         },
         function() {
             $(this).animate({ left: '0' });
         }
     );
});

Check out the Demo here!

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

Error: Unable to locate or read the file "style.scss" for import

I'm currently in the process of setting up a new vuejs project from scratch, but I've encountered an error when trying to import "style.scss" into my component. Specifically, the issue arises in the Login.vue file where I include the style.scss. ...

Encountering a problem with inline fields in CSS Bootstrap 4

Trying to get my form set up (without being a CSS expert), I've managed to create the following input layout that is close to what I want: https://i.sstatic.net/EjVAq.png However, all input fields in the same group are the same size (1/2 for name gr ...

Utilizing Node.js with Express and Swig to seamlessly pass a local JSON file to a template

I am new to working with nodes, and I have successfully managed to integrate Express/swig and display them on the screen. However, when I include my d3 code (which functions independently), I encounter an error in the console: Uncaught TypeError: Cannot re ...

Encountered an error when attempting to use the 'removeChild' function on a node that is not a child of the specified node. This issue arose while interacting with an input box

I recently created a todo app with a delete functionality. However, after deleting an element successfully, I encountered an error when typing in the input box stating: Failed to execute 'removeChild' on 'Node': The node to be removed i ...

Saving maps on React Native can be done easily using AsyncStorage

I am facing an issue with saving user inputs as a JS map using AsyncStorage in my React Native app. Despite no errors during the saving process, I encountered "[object Map]" when attempting to retrieve the data. Here is a simplified version of my user map ...

"In the most recent version of THREE.js (r82), the shadow is not detectable

I am having trouble casting a shadow from a cube onto a plane using MeshLambertMaterial in my code. Despite setting up the scene correctly, the shadows are not appearing as expected. Most solutions I have come across suggest that objects should be within ...

Managing JSON data structures

In the process of developing a Chrome extension that is intended to extract the YouTube video IDs of the top 3 search results based on an input string, I have encountered a roadblock. The current code snippet looks like this: var items = []; function get ...

First-time binding of data in d3.js did not occur

I need help analyzing the following dataset: [{ label: "ABC", p1: "23", p2: "3" }, { label: "EF", p1: "4", p2: "10" }, { label: "GV", p1: "5", p2: "15" }, { label: "FD", p1: "9", p2: "5" }, { label: "SDF", p1: "20", p2: "10" },] My at ...

The footer and login form are tangled up in a web of confusion

Here is my HTML code for a login form: <div class="middle-box text-center loginscreen"> <div> <form class="" role="form" action="index.html"> <div class="form-group&q ...

NextJs Link component does not refresh scripts

While using the <Link> tag in NextJs for page navigation, I encountered an issue where my scripts do not rerun after switching pages. The scripts only run on the initial page load or when I manually reload the page. This behavior is different when us ...

When I executed this code, an error occurred stating that `router.use()` expects a middleware function, but received a different type: ` + gettype(fn)

//jshint esversion:6 const express = require("express"); const bodyParser = require("body-parser"); const app = express(); app.use("view-engine", "ejs"); app.get("/", function(req, res){ var today = new Date(); var currentDay = today.getDay(); var d ...

Is there a way to potentially utilize window.open() to open a specific section of a webpage?

My HTML page consists of 2 div blocks and 2 links. I want to open the content of the first div in a new window when the first link is clicked, and the content of the second div in another new window when the second link is clicked. You can find the code h ...

How to pass a variable or value through the async await API in the Vue.js and Laravel integration?

I'm facing an issue with my API where I want to check if a given email exists in the database, but every time I run it and view the console log, it returns undefined. Can anyone here suggest a better code snippet or approach for this? I specifically w ...

Adjust the size of an array based on the specified index

I have an array defined as... let myArray = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13] ...along with a starting index let start = 2 and an ending index let end = 5. I want to resize the array by taking elements from start to end, for example: start ...

Align breadcrumbs to the left in Bootstrap 4 while keeping the text aligned to the right

I am striving to achieve something similar to this: Example Currently, I have the following setup: <nav aria-label="breadcrumb"> <ol class="breadcrumb"> <li class="breadcrumb-item>Home </li> <li class="breadcrumb-item>Level ...

Learn how to access a variable within the Watch function using a directive in Angular framework

I'm new to Angular and encountering some issues with the watch function. I am trying to track changes in a variable inside a controller, and once the value of this variable changes, I want to pass that updated value to a directive. Below is the code ...

Having trouble with the functionality of Bootstrap 5 carousel?

I've been attempting to integrate this carousel into my Bootstrap 5 webpage. I found it on Codepen - https://codepen.io/sahil-verma/pen/wxXryx Thus far, I've copied the code into my webpage and linked the corresponding CSS within style tags, sim ...

Uploading files via an HTML form

I am facing an issue while attempting to save a file uploaded from a form. Despite following the tutorial on the w3schools website, I keep encountering an error stating 'Undefined index: userpic' in C:\wamp\www\HW4\confirm.php ...

Leveraging AngularJS to fetch data from two distinct JSON files

I am faced with the challenge of incorporating 2 JSON file examples into my project. The format of each file is different, so I am exploring the best approach using an angular controller to handle them effectively. These JSON files are not being fetched fr ...

JSDOM failing to retrieve complete list of elements from webpage

I'm currently struggling with a simple webscraper using JSDOM. Here's the code snippet I've been working on: const axios = require("axios"); const jsdom = require("jsdom"); const { JSDOM } = jsdom; let v = "15" ...