The keyframes animation for the navigation bar will not restart from a different location

I've been working on creating a CSS keyframes animation for a navigation bar, and I'm encountering some issues. The animation involves a red line moving when a user clicks on a nav bar element. By default, the first element is active (red line under it), and when clicked, JavaScript combines properties of the animation element and the clicked element into new keyframes.

The animation works smoothly from element 1 to 2 and 1 to 3. However, there's a problem when attempting to play the animation from element 2 to 3 after going from 1 to 2. Despite checking the animationend event, I couldn't find a solution by removing or reattaching the animation class or changing the animation-play-state property.

Researching various methods didn't yield a fix either. Avoiding brute force creation of multiple keyframes rules, which would be tedious and unscalable with more elements in the nav bar, is my goal. I'd like to keep the code flexible and applicable across different scenarios.

If you have any suggestions or insights on how to resolve this animation issue, feel free to share. Thank you!

~ Code Snippet ~

// Your JavaScript code here...
// Your CSS code here...
// HTML markup example...

Answer №1

That's an intriguing question. I'm not entirely certain why the event isn't re-triggering in this instance, but let me propose a few adjustments to your approach:

The tricky part of this effect involves managing the opacity of each line. I've utilized animationEnd to assist with this, and it seems to be functioning adequately.

Further comments are included in the example code. Enhancements could involve handling clicks during active animations, consolidating animation functions, etc. Additionally, you might want to vary the animation duration based on the number of items.

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

Incorporating personalized jQuery (modal window) into a WordPress site

I created a unique jQuery modal/pop-up and now I am looking to integrate it into my WordPress site. HTML <div id="customDialog"> <form id="myForm" method="post"> <br><br><br> <p id=title name=title><b>S ...

Basic $http.get request including parameters

I've been attempting to send an HTTP request using the AngularJS $http service like this: $http.get('http://myserver:8080/login?', { params: {username: "John", password: "Doe" }, headers: {'Authorization': ...

"Double the Data: A D3.js JSON Tale of Two Creators

I found inspiration from this example: http://bl.ocks.org/mbostock/1062288 to create a collapsible Force Layout. One challenge I'm facing is how to display a graph where a single node is connected to two parent nodes. father father | | ...

The MVC controller is not receiving any data when an Ajax post is made

This piece of code is triggering an AJAX call: $.ajax({ url: '/Merchant/SaveDirty', type: 'POST', dataType: 'json', data: ko.toJSON(dirtyItems), contentType: ...

Angular's $q.defer() function will yield an object with a "then" function

In my Angular file, I am attempting to access a database using $http and then store the retrieved data in a $scope variable for display on the webpage. However, I am encountering difficulties with $q.defer not running as expected. When I check the consol ...

Displaying values dynamically as they transition between states in Reactjs

There are four components that I'm working with - UserHome, SearchFlight, Events, and Alerts. The UserHome component is where I import all the other components: <SearchFlight/> <Events /> <Alerts /> Within the SearchFlight compone ...

Having trouble interpreting PHP-generated JSON data in JavaScript

I have a PHP script that outputs a JSON string. <?php $arr = array( 'id' => '1', 'myarray' => array( array('a' => 'a1', 'b' => 'b1', 'c' => 'c1', & ...

What is the best way to center these two buttons within a div?

Is there a way to ensure that the two buttons align properly within their parent div, which has a fixed width defined as either a specific number or percentage? A visual representation of what I am seeking can be viewed in the image below: https://i.sstat ...

Is it acceptable to use JavaScript to code positioning if the standard HTML flow is not behaving as expected?

After contemplating for a long time, I have finally mustered the courage to ask this question. The behavior of HTML elements in normal flow has always bewildered me. Controlling them can be quite challenging, especially when dealing with server-side coding ...

Checking the next route in Angular 2 when navigating away

Is there a way to trigger an action only on specific NavigationEnd router events, excluding when navigating between child routes or on a particular route? This is a snippet from my app.routing.ts: // other route configurations... { path: 'scrapers/ ...

Changing the link color within a repeater in ASP .NET when it is clicked

The given code snippet is being executed on an iPhone 4, causing some CSS elements like Hover to not function as expected. <asp:Repeater ID="rpt" runat="server"> <HeaderTemplate> <div class="table withshadow"> </Header ...

jquery animation does not reset after event occurs

My script is functioning well to animate my elements, but I am facing an issue where when the function is called again after a timer, the elements move to their correct positions but do not initiate a new animation. The goal of the function updateFlights( ...

After cloning the variable from props, the Vue 3 Composition API variable becomes undefined

I have a main component containing code and tables, including a modal that is displayed based on a boolean value. The main component features the following modal: <ConfirmPaymentModal ref="confirmPaymentModal" :invoice="markAsPa ...

Retrieving a value in the app component from a map using Angular

I have been struggling to display the values of ValueM, ValueR, and product in my app.component.html file. Can anyone offer a solution or tip to help me move forward? Thank you very much. app.component.ts forkJoin( this.service1.method1(filter1), ...

Navigating Between Web Pages

Hello there! I'm curious to learn how I can establish routing between multiple pages. Specifically, I have an index page and I'd like to navigate to other HTML pages within my views folder. Is it possible to achieve this without relying on the An ...

Setting a menu item as active in a SvelteKit app: A step-by-step guide

I encountered an issue with the main navigation menu in my sveltekit application. The problem is that when the app is loaded or refreshed, the active menu item corresponding to the current URL is not set. After struggling to find a solution online, I manag ...

Harnessing the power of JavaScript to dynamically extract data from JSON formats

My goal is to extract multiple strings from a JSON object and combine them into one large string. Initially, I thought it made sense to use a loop that would add each new string during each iteration. However, upon implementation, some unexpected errors ar ...

Ways to access the content of the chosen <td> element using Vue?

I have a dynamic table where I retrieve data using $.ajax() from a database. The content in the rows is editable, and I need to save the changes made with vue.js. After updating the content, an $.ajax() function with 4 parameters (name, client_id, url, and ...

When attempting to convert an Image URL to Base64, the image is not displaying

I'm currently in the process of converting an image to Base64 from a given Image URL using canvas. The method I'm following is somewhat similar to the references provided in the links below, however, the resulting Base64 string doesn't seem ...

Refresh inventory of items using AJAX

Can someone assist me in finding where I made a mistake? I am trying to update the list of comments using ajax after successfully adding one, but instead, I end up seeing this page.https://i.sstatic.net/X7WZi.png The new comment is added to the database, ...