Unable to activate transition-delay property when switching classes

I have a scenario where I am using jQuery to add and remove a class from the parent element (body). However, I noticed that the transition-delay property seems to be behaving differently in different browsers. It works fine in Safari but breaks in Chrome and Firefox.

Specifically, when I click on the first list item, it should move only after the other list items have disappeared.

However, when I click the back button, the list item should return to its original position, and then the other list items should reappear. The issue is that upon clicking back, the transition-delay on opacity is not respected, causing the items to immediately appear instead of fading in.

I am looking for a solution or workaround to fix this problem. Any suggestions would be greatly appreciated!

$('#one').click(function() {
  $("body").addClass("move");
});

$('#back').click(function() {
  $("body").removeClass("move");
});
ul {
  width: 300px;
  height: 150px;
  margin: 0;
  padding: 0;
  list-style: none;
  position: absolute;
  bottom: 0;
  right: 0;
}
ul li {
  height: 50px;
  display: block;
  margin: 0;
  padding: 0;
  background: lightgreen;
  transition: 500ms transform ease-in-out, 500ms opacity linear;
  opacity: 1;
  transition-delay: 0, 500ms;
}
body.move ul li#one {
  transform: translateY(-100vh) translateY(150px);
  transition: 500ms transform ease-in-out;
  transition-delay: 500ms;
  opacity: 1;
}
body.move ul li {
  opacity: 0;
  transition: 500ms opacity linear;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<ul>
  <li id="one">One</li>
  <li id="two">Two</li>
  <li id="three">Three</li>
</ul>
<a id="back">Back</a>

https://jsfiddle.net/m3e7sm8k/5/

Answer №1

Instead of using this syntax:

transition-delay: 0, 500ms;

It is recommended to use the following syntax:

transition-delay: 0s, 500ms;

Some browsers may not support a unitless time value like 0. While the CSS spec does not explicitly forbid it, it seems that using 0s consistently is safer. It's best practice to avoid unitless time values in this context.

CSS Spec reference: 2.4. The transition-delay Property

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

Images in assets folder are not showing up in Vue Bootstrap

I'm attempting to showcase an image similar to the example provided in this guide Below is the code I am using: <template> <b-container fluid class="p-4 bg-dark"> <b-row> <b-col> <b-img rounded="ci ...

What are the steps for creating personalized sliders with WordPress?

Seeking guidance on how to code WP Template files to enable control from the WP dashboard for adding or removing slider images. A sample code snippet is provided below. <div id="myCarousel" class="carousel slide" data-ride="carousel"> <!-- Indi ...

Using HttpURLConnection along with Response (Content-Type: text/html) on android: Tips and tricks

Can someone help me with the Android code using HttpURLConnection to receive a response? The Request and 2 Response are as follows: Request [Headers Authorization: ******] Response [code: 302, Headers (Content-Type: text/html)] Response [code: 302, ...

What's the best way to add click functionality to a bootstrap 5 card

I am currently learning Bootstrap 5, html, and CSS. I am using these technologies to develop a website and implementing Bootstrap 5 to create cards. I wanted to make these cards clickable so that they can redirect users to another page on the website. Howe ...

When my website is viewed on a local server, it is responsive and utilizes flex and bootstrap. However, now that it is hosted online, the flex function is not working properly on the mobile site

As a novice web developer, I've created a portfolio site hosted at www.j-price.co.uk. However, I've encountered a responsiveness issue after hosting it on GitHub Pages and GoDaddy. The site displays differently compared to when it's hosted l ...

How do I disable scrolling while the animation is running in CSS?

Is there a way to disable scrolling while animating in CSS without using overflow:hidden on the body tag? ...

What is the best way to create a layout with two columns containing SVGs and text, ensuring that the text consistently appears to the right of the SVG

My webpage has two columns, each containing an SVG and some text. However, when I resize the window in Google Chrome, the text drops below the SVG before the window width goes below 600px. How can I prevent this from happening while maintaining a constant ...

Tips for JavaScript code to tally occurrences of a designated word within HTML content

I am trying to create a script that will count the occurrence of a specific word or phrase in an HTML body, such as within a paragraph. One unique feature I am looking for is the ability to count by matching with a variable - which represents a string rath ...

Switching the endpoint renders the middleware ineffective

I've encountered a puzzling issue with my NodeJs - Express server, which serves as the backend for my mobile application. The problem arises when I send post requests to certain endpoints like checkmail and checkusername using axios from the frontend ...

What is the best way to conceal the dt tag when the dd tag contains no value

Is there a way to hide the "Subject" if the "subject_title" field is empty? <dt class="col-sm-6 text-dark" >Subject</dt> <dd class="col-sm-6">{{$course_dtl->subject_title }}</dd> For example, I would li ...

jQuery fails to update the CSS3 animation speed dynamically in IE10

I am currently working on a side project that involves using moving divs with @keyframes and CSS3's animation property. Initially, I faced difficulties in getting this to work smoothly on webkit browsers due to issues with transform3d. However, after ...

Dealing with content extending into the previous column within CSS columns

I used this code pen example to perfectly illustrate the concept. To demonstrate, I applied the following CSS code. Try hovering over the second card in the top row. .custom-hover:hover { transform: scale(1.5); } In essence, when the top element of a ...

The command `browser.find_elements_by_class_name('foo')` returned zero results

I'm encountering an issue with selenium while using Python 3.7. The website I'm working on has a structure similar to this: <html> <body> <div class="foo"> <div class="bar1">some ...

Employing jQuery for element rotation via swipe/drag movements

I am looking to create a dynamic experience where a circle rotates in sync with the user's swipe or drag gestures on the screen. Currently, I am developing an app using Phonegap and considering integrating hammer.js as it comes highly recommended by m ...

Strategies for iterating through a collection of responses once and showcasing exclusively the incorrect ones

Let's consider the following as the correct and incorrect answers for each question: Question Number: 1 Correct Answer(s) B Incorrect Answers A C D Question Number: 2 Correct Answer(s) A C Incorrect Answers B D Question Number: 3 Correct ...

Why is the text getting covered by the drop down menu?

I am currently working with bootstrap classes and I am facing an issue where the drop down menu is overlapping with the text. You can see the problem in the screenshot here: enter image description here <div class="collapse navbar-collapse" ...

Clicking the Ajax jQuery button triggers a change in color, as well as toggling the value of a column between true and false

Trying to figure out this chart ECDLpayments -> ecdp_Payed = boolean true or false Managing the system public function addUserPayments() { if (Request::ajax()) { $input = Input::all(); $newpayment = new ECDLPayments(); ...

Creating an HTML structure that limits each li to only contain three div elements can be achieved using React and Underscore.js

To achieve this specific layout, I am looking to utilize only underscore.js functions. Below is the array that I have: var xyz = [{ 'name': 'test' },{ 'name': 'test1' },{ 'name': &ap ...

Troubleshooting: Issues when using jQuery metisMenu in conjunction with *ngIf

We are facing an issue while using the metisMenu with Angular2. There is an *ngIf condition on one of the list items, and its visibility changes based on whether a record is selected. When the li item is shown for additional options, it does not work prope ...

HTML header with zero margin

Hi there! I am currently learning the basics of HTML and CSS. I have a question regarding creating a header with no margins on the edges. Any advice would be greatly appreciated as I haven't been able to find a clear solution. Below is my code snippet ...