The HTML "details" element does not support repeated animations in Chrome

My goal is to animate elements within the summary section of an HTML details element. Interestingly, Firefox executes the animation perfectly and it repeats each time I open or close the details. However, on Chrome, the animation only runs when the details is first opened and never again.

details {
  font-size: x-large;
}

details[open] ul li {
  animation: expand-details 1s ease-in-out;
}

details[open] ul li:nth-child(1) {
  animation-fill-mode: backwards;
  animation-delay: 100ms;
}
details[open] ul li:nth-child(2) {
  animation-fill-mode: backwards;
  animation-delay: 200ms;
}
details[open] ul li:nth-child(3) {
  animation-fill-mode: backwards;
  animation-delay: 300ms;
}

@keyframes expand-details {
  from {
    opacity: 0;
    left: -20px;
  }
  to {
    opacity: 1;
    left: 0;
  }
}
<details>
  <summary>Click me to open an animated list of items</summary>
  <ul>
    <li>These elements</li>
    <li>should ease in</li>
    <li>with a duration of 1s.</li>
  </ul>
</details>

How can I ensure that the animation restarts in Chrome whenever I close and reopen the details element?

Answer №1

After experimenting with some Javascript, I managed to find a clever solution.

function detailsToggled(e)
{
  if (e.srcElement.open) return;

  const copy = document.createElement("details");
  copy.innerHTML = e.srcElement.innerHTML;
  copy.addEventListener('toggle', detailsToggled);

  e.srcElement.parentNode.replaceChild(copy, e.srcElement);
}
// Apply the event listener to all details elements on the page
document.querySelectorAll('details').forEach(d => d.addEventListener('toggle', detailsToggled));
details {
  font-size: x-large;
}

details[open] ul li {
  animation: expand-details 1s ease-in-out;
}

@keyframes expand-details {
  from {
    opacity: 0;
    left: -20px;
  }
  to {
    opacity: 1;
    left: 0;
  }
}
<details>
  <summary>Test</summary>
  <ul>
    <li>one</li>
    <li>two</li>
    <li>three</li>
  </ul>
</details>

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

The jQuery function is not functioning correctly

Currently, I am in the process of setting up an accordion menu using jQuery and CSS3. Everything is working perfectly fine so far except that the menu always opens upon page load and the code to hide it is not functioning as intended. Here's the link ...

The importance of precision in a written text

When it comes to being specific, I usually pride myself on my skills. However, there's one particular challenge that I can't seem to crack. Here's the scenario: Imagine you have a list structured like this: <ul class="dates"> < ...

Numerous divs positioned above a myriad of images

Is there a way to create multiple images with a tag name overlaying each one as a link? I've been able to add a tag name on top of one image, but not on others. Every time I try to duplicate the div containing the image and tag, the tags do not show u ...

As soon as I hit the submit button on my website form, the URL is automatically refreshed with the information I provided

I am a beginner when it comes to forms and recently copied and pasted this login snippet code: <div class="login-form-1"> <form id="login-form" class="text-left"> <div class="main-login-form"> <div class="login-group"> ...

- Lorem ipsum dolor sit amet, consectetur adipiscing elit

I am looking to create a list with lower-roman indexes that are enclosed in parentheses (ii), where the content of each item is indented. Here is an example: (i) lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer ut metus nec urna ...

Ways to animate a main element independently of its counterpart's animation

I want to create an animation for a parent element without affecting the child's animation. My HTML & CSS structure is set up as follows: .parent{ background-image: url('https://pm1.narvii.com/6195/421ddbf8c9a2fb1715ef833f869164dc1be ...

The hover functionality for the cursor's pointer is malfunctioning

I currently have two div elements in my HTML code: <div id="hm-sp-lenovo-wr"> ....... <div id="hm-sp-motorola-wr"> ....... In my stylesheet, I have defined the following CSS rules: #hm-sp-lenovo-wr:hover { cursor: pointer } #hm-sp-motorol ...

`Is it possible to modify the background color of InputAdornment in Material-UI TextField?`

For the first 10% of the text field, one background color is used, while for the remaining 90%, another background color is applied. <TextField className={classes.root} type="text" placeholder="username" var ...

Using PHP and MySQL to handle data submission through the POST method

When I send data to post[submit] and post[request], it's coming from two separate buttons. Even though I successfully submitted user_id to post[submit], I'm encountering difficulty in echoing the user_id in the request portion (post[request]). ...

Bootstrap and jQuery for creating columns of equal height

I'm currently utilizing Bootstrap in a web project and struggling to dynamically set the same height for column elements. I am aware of the .row-eq-height class, but using it compromises the responsiveness of Bootstrap elements. My goal is to ensure t ...

Unable to display background image on Webpage due to blank page issue while uploading it with HTML and CSS

I've been attempting to build a webpage with an image as the background, but I seem to be facing some issues. Instead of seeing the desired image, all I get is a blank white page. The folder named "images" is located in the same directory as my HTML a ...

Having trouble making :hover work properly

I've been attempting to create a mega menu that activates divs on hover, but I just can't seem to get it to work. I've tried various methods, but the divs simply won't show when hovered over. If you'd like to take a look, here&ap ...

How do I create a sliding dropdown notification bar?

Can anyone provide some guidance on how to create a sliding dropdown section for my homepage, similar to the one on this website: . (Please note, be cautious of potential malware) I'm interested in replicating the dropdown section that says "call for ...

Is there a way to verify the phone number input field on my registration form along with the country code using geolocation

I'm currently working on a registration form that includes an input field for telephone number. I'd like to implement a feature where, upon filling out the form, the telephone input field automatically displays the country code by default. Would ...

Tips for avoiding the need to reload a single page application when selecting items in the navigation bar

I am in the process of creating a simple Single Page Application (SPA) which includes a carousel section, an about us section, some forms, and a team section. I have a straightforward question: How can I prevent the page from reloading when clicking on nav ...

Creating a banner using four grid elements, with each element containing four child elements, is a simple process that can

Can you assist me in recreating my idea from an image? I am having trouble understanding how to select and place other elements, and then return them to their original positions after deselecting... I attempted to use a grid but it did not work properly. ...

Exploring the Power of JQuery with Hover Effects and SlideToggle

I was struggling to keep the navbar displaying without it continuously toggling when my pointer hovered over it. I just wanted it to stay visible until I moved my pointer away. <script> $(document).ready(function(){ $(".menu-trigger").hover(funct ...

Enhancing django signup form with personalized helper texts using widget_tweaks

I am running into an issue with the helper text for the Password field on my signup page using Django's default signup form. Despite my efforts, I can't seem to resolve it. Below is the body of my signup.html: <body class="text-center"> ...

Is there a way to enlarge images when hovered using canvas?

I came across a fascinating example at the following link: , where the images expand when hovered over. I am aware that this can be achieved using jquery, but I have concerns about its speed and reliability. I would like to experiment with d3.js, although ...

Render inline CSS styles with AngularJS

Can we use angular variables to write inline CSS styles? <div style="background: transparent url({{eventInfo.eventHeaderImg}}) top center no-repeat;"></div> Here is the output I received: "NetworkError: 404 Not Found - http://test/eventInfo. ...