Sequential queuing of transitions in CSS3

Is it possible to queue CSS transitions with the same properties? My goal is to translate an element to a specific position (with a transition duration of 0) before translating it again.

For example, in this mockup, clicking "move" should move the box 100px to the right before translating it 100px to the left.

  1. Why doesn't this work? Does the second transition overwrite the first one?

https://jsfiddle.net/aqwaypoh/3/

  1. I found a solution that works by using a non-zero transition duration (0.01), otherwise the transitionend event doesn't fire.

https://jsfiddle.net/dpv3xzth/5/

Although I was able to fix the issue of the transitionend event firing twice in Chrome, I'm wondering if there is a better way to achieve this without relying on the end event or a timer?

If possible, I would prefer to write this without using the end event or timer. Is there a more efficient approach?

<div class="box"></div>
<a href="#" class="move">move</a></a>

Answer №1

Latest Update:

You have the option to utilize the CSS3 animation property along with @keyframes.

.box.animate {
  animation: move 2s;
}

@keyframes move {
  0% {
    transform: translate(100px);
  }
  100% {
    transform: translate(0px);
  }
}

To trigger the movement of the box, simply add the class animate to your element. Alternatively, you can define the animation property directly in JavaScript based on your preferences.

box.addClass('animate')

Check out the jsfiddle demonstration: https://jsfiddle.net/aqwaypoh/7/

Answer №2

If you add a timeout to the second condition, you should achieve the desired result.

var container = $('.container'),
  button = $('.button').click(function() {
    container.css({
      "transform": "translate(100px)",
      'transition-duration': '0s'
    });

    setTimeout(function(){
       container.css({
         "transform": "translate(0px)",
         'transition-duration': '0.5s'
       });
   }, 1);
  })

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

Transferring form data to an external webpage and fetching the HTML response from the server

Is it possible to retrieve the HTML or plain text from the result of a form sent to an external page? I have a form that sends variables to an external server and the result goes to an iframe. How can I retrieve the HTML or text from the iframe? I'm ...

Using JQUERY to create a dropdown menu that dynamically changes based on the date field

I am currently working on a JQUERY project and facing a challenging situation. I usually know how to create dropdown menus that depend on one another, but this time I need a dropdown menu that displays age ranges based on the date entered in the birth-date ...

The font from the server is not displaying correctly in the local HTML file

After uploading the ttf font file to the server, I utilized the following CSS code: @font-face { font-family: "fontname"; src: url("http://www.mywebsite.com/Fonts/fontname.ttf"); } body { font-family: "fontname", sans-serif; } Within the loc ...

Change classes of sibling elements using Angular 2

Imagine you have the following code snippet: <div id="parent"> <div class="child"> <div class="child"> <div class="child"> </div> I am looking to automatically assign the class active to the first child element. ...

The div's coloring extends beyond the margins

My page is set at a width of 970px. Everything looks good, with the paragraph aligned within the margin. However, when I try to apply color, it extends outside the margin. <div class="container"> <header> <nav c ...

Transferring a JavaScript variable to C# to execute an SQL SELECT query, then sending the returned result back to JavaScript

I am facing an issue while trying to execute code in my Code Behind to query my SQL Server using a JavaScript variable and then return the result as an Integer back to my Javascript. My approach involves running some Javascript code initially to obtain a ...

Classes aren't displaying properly for elements inside

Is there a way to display the header only in a small size using the col-sm-* class of the div inside a container? It seems like the col-sm-* class is not working correctly and not floating them properly. <link href="https://maxcdn.bootstrapcdn.com/b ...

What could be causing the element.style.FontSize to not be effective on classes that have been looped through and stored in an array created with querySelectorAll beforehand?

Greetings Stackoverflow Community, Today, I'm facing an issue related to JavaScript and WordPress. I have a JavaScript script named setDynamicFontHeight.js, as well as PHP documents named header.php and navbar_mobile.php, which simply executes wp_nav_ ...

"I seem to be unable to retrieve all the data points for the X and Y axes on my nvd3 graph. Could there be some options that I am

https://i.sstatic.net/ITbJm.png I am encountering difficulty in obtaining all the X and Y intersection points on the axis as shown in the graph image. Additionally, I would like to emphasize the intersection points with a dark circle. Any assistance in re ...

What methods can be used to protect (encrypt using Java code) the information in a login form before it is sent to a servlet for

One major concern I have involves sending encrypted data (encrypted before sending the request) to a servlet. I attempted to call a function that encrypts passwords as an example, but I encountered difficulty passing values from JavaScript to Java code in ...

Organize express controller by breaking it up into multiple separate files

Recently, I've set up an express js controller file as follows The File Path: /controllers/usersController.js // Register User module.exports.register = function(req, res) { ... } // Login User module.exports.login = function(req, res) { ... } // ...

Inspect Element - base tag href URL for inline CSS allocation

When utilizing the <base> tag in HTML along with the <style> tag on Microsoft's Edge Browser, I encounter a peculiar issue. Here is a very basic example: <!DOCTYPE html> <html lang="en"> <head> <title>Edge de ...

Exploring the world of jQuery waypoints and the art of modifying

This is only the second question I'm asking here, so please be gentle! I've been experimenting with jQuery waypoints to dynamically show and hide a border under my navigation menu based on scroll position. For instance, when the sticky nav is ov ...

Streamlining all icons to a single downward rotation

I am currently managing a large table of "auditpoints", some of which are designated as "automated". When an auditpoint is automated, it is marked with a gear icon in the row. However, each row also receives two other icons: a pencil and a toggle button. W ...

What is the best way to handle the return value from using indexOf on a string?

I am looking to manipulate the value returned by a specific conditional statement. {{#each maindata-hold.[2].qa}} <div class="section"> <a href="javascript:void(0)" class="person-link" id="{{id}}"> <span class="name- ...

Strangely compressed HTML image

I am facing an issue with using a base64-encoded png retrieved from a server in WebGL. To incorporate the encoded png, I load it into an html Image object. For my specific needs, it is crucial that the png data remains completely lossless, however, I&apos ...

Pause a YouTube video automatically when the window is not in focus using FancyBox

I have successfully implemented dynamic play/pause functionality for a YouTube video, as demonstrated in my weave. However, I am facing challenges in making it work dynamically with FancyBox using the onBlur event (to pause the video when the window is no ...

PHP Query Composer/Reporter

As I work on fine-tuning a web application, the support and explanations from members of this community have been incredibly valuable. I appreciate the assistance in simplifying complex concepts. One feature I wanted to include in my app was the capabilit ...

What is the best way to utilize *ngFor for looping in Angular 6 in order to display three images simultaneously?

I have successfully added 3 images on a single slide. How can I implement *ngFor to dynamically load data? <carousel> <slide> <img src="../../assets/wts1.png" alt="first slide" style="display: inline-blo ...

Modifying the default class styles from Bootstrap based on the HTML displayed in Devtools

I am attempting to customize the styles of my application using bootstrap. Upon inspecting the HTML in Chrome Devtools, I found the following rendered code: <div data-v-256a5f3d="" data-v-7bf4ea52="" class="row bg-gray-200 bord ...