Ways to Halt Every Single CSS Animation

Is there a way to stop all CSS animations in a document from the beginning? My idea is to assign a class to elements containing CSS animations at the start, such as '.paused'. Then, using jQuery in my JavaScript, I would remove the '.paused' class with a callback function and add a new class to resume playing, like '.running'.

This is what I currently have:

HTML:

<li class="firstanimation paused">...</li>
<li class="secondanimation paused">...</li>
<li class="thirdanimation paused">...</li>

CSS:

#slider li.paused {
    -webkit-animation-play-state: paused;
    -moz-animation-play-state: paused;
    -ms-animation-play-state: paused;
    -o-animation-play-state: paused;
    animation-play-state: paused;
}
#slider li.firstanimation {
    animation: cycle 25s linear infinite;-moz-animation:cycle 25s linear infinite;-webkit-animation:cycle 25s linear infinite;
}
#slider li.secondanimation {
    animation: cycletwo 25s linear infinite;-moz-animation:cycletwo 25s linear infinite;-webkit-animation:cycletwo 25s linear infinite;
}
#slider li.thirdanimation {
    animation: cyclethree 25s linear infinite;-moz-animation:cyclethree 25s linear infinite;-webkit-animation:cyclethree 25s linear infinite;
}

I am facing an issue where the "#slider li.paused" selector is not working. Chrome's inspector states that 'animation-play-state: paused;' is an invalid property value... why is that happening when I already have a similar CSS rule that works fine?

#slider:hover li, #slider:hover .progress-bar {
    -webkit-animation-play-state: paused;
    -moz-animation-play-state: paused;
    -ms-animation-play-state: paused;
    -o-animation-play-state: paused;
    animation-play-state: paused;
}

To sum it up, how can I target all animations with a specific class to ensure they are all paused? The W3 docs state that 'animation-play-state: paused;' should work for all elements, pseudo-elements included, but it's not working in my case. What could be causing this issue?

Your assistance on this matter would be highly appreciated.

Thanks in advance!

Answer №1

The issue you are facing is related to the specificity of selectors. When both .paused and li.elemclass have equal specificity, the compiler will prioritize the one that comes last.

To resolve this, consider rearranging the properties for .paused after the others or increase its precedence by adding an additional layer like body #slider li.paused

For more detailed information on specificity, refer to the documentation. Additionally, you can use a specificity calculator tool for your convenience.

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

A combination of fixed width column and dynamic content area in Bootstrap design

Is there a way to achieve the combination of fixed and fluid width columns using Twitter Bootstrap alone, similar to this example? The HTML and CSS in the example make it seem simple. But can this be done solely with Bootstrap? ...

Tips on choosing a button and applying custom styles with emotion styles in MUI

Looking to apply a margin-right to my button. Currently utilizing mui 5 with Button variant='contained'. I created a custom CSS style using the styled component in mui and targeted the Box. const Wrapper = styled(Box)({ display: 'flex&ap ...

An undefined error for the variable 'y' in a JavaScript AJAX scenario

I'm completely new to JavaScript and struggling with writing a code that dynamically counts the words on a webpage. Currently, this piece of code is enclosed within a 'whenkeydown' function: var text = $(this).val(); var word=text.split(" ...

Drag a dropdown menu to the bottom left corner and set it to full width on mobile using CSS

Check out this code snippet with CSS and HTML: CSS .flyout { position: absolute; top: 30px; right: 15px; background-color: #FFF; padding: 20px; border: 1px solid #eaeaea; z-index: 999; width: 400px; border-top: 3px solid #337AB7; disp ...

Applying CSS blur filter to container without affecting its content

I'm trying to create a hover effect where an image within a parent div transitions into a blurred state. However, I've run into an issue where if the image is set to 100% width/height of the parent div, there is a visible bezel of the parent&apos ...

Ensure the presence of an editable column within a table using a jQuery function

Within the table, the first column is editable. Upon making a change to it, I want an alert to appear indicating that a change has occurred. The check function is being called after a delay of 5000ms. Embedding Code Snippet for Reference I suspect there ...

Converting Ajax to JSON with Jquery offline and Manifest for enhanced offline web applications

Looking to create an offline web application, I'm in the process of transitioning from Ajax to JSON using JQuery offline. Here is the initial Ajax code: $.ajax({ url: contentpage, data: contentpagedata, cache: false }).done(function( html ) { ...

Tips for Implementing Color-coded Manchu/Mongolian Script on Your Website

My journey began with a seemingly straightforward task. I had a Manchu word written in the traditional script and I wanted to change the color of all the vowels in the word (ignoring ligatures). <p>ᠠᠮᠪᡠᠯᠠ ᠪᠠᠨᡳᡥᠠ</p> < ...

jQuery - Password Validation

I need help using jQuery to validate two password fields against each other. Below is the code snippet I am currently using: jQuery('#settingsForm').validate( rules : { npassword : { }, pass_check : { equ ...

What are some ways to handle the unique selected text behavior of the jQuery MaskedInput plugin?

Apologies for the lengthy title of this question, but I struggled to find the right wording. The problem lies in the fantastic Masked Input jQuery plugin created by Josh Bush. When using a fixed-length mask, it selects the input text upon focus. However, ...

Iphone not picking up media queries, while browser resize is working perfectly

Hey there, I'm currently using a theme called Bones on my WordPress site, but I'm encountering some difficulties with the responsive menu on my iPhone. Oddly enough, when I manually resize the window, the menu seems to work just fine. Here' ...

jQuery is not recognizing the checked state of a checkbox when it is modified dynamically

$("#submit_load").click(function() { var profilename =$("#search_profiles option:selected").attr("value"); var data='profilename='+profilename+'&user_id=' + <?=$user_id;?>; alert(data); $.ajax({ //this is ...

Choose the div without a class

I currently have several divs displayed on my website. <div class="slide bx-clone"></div> <div class="slide"></div> <div class="slide"></div> <div class="slide bx-clone"></div> <div class="slide bx-clone" ...

Updating HTML label values using jQuery in a loop based on their index position

I am having an issue with my ajax call where I want to loop through each label in a class and set their value to the response returned from the server. However, the current code sets all labels to the same value instead of setting individual values based o ...

Switch from scrolling the entire page to scrolling within a single div

Whenever I click on an element on my webpage, a modal window with a fixed position appears. The issue I am facing is that when I scroll using the mouse or touch gestures on my phone or tablet, the entire page scrolls instead of just the content within the ...

What is the process for developing multiple screens or views in PhoneGap?

Currently working on a reading app and decided to give phoneGap a shot for the first time. I'm pretty proficient in HTML, CSS, and JS, but not very familiar with xCode. In this app, I plan to have a button on the home screen that redirects users to an ...

Basic JavaScript framework centered around the Document Object Model (DOM) with a module structure similar to jQuery. Currently facing challenges with

In order to create a simple framework with jQuery style, I have written the following code: (function(window) { window.smp=function smpSelector(selector) { return new smpObj(selector); } function smpObj(selector) { this.length = 0; if (!s ...

Populate an array with the present date and proceed in reverse order

In my code, there is an array that has a specific structure: var graphData = [{ data: [[1, 1300],[2, 1600], [3, 1900], [4, 2100], [5, 2500], [6, 2200], [7, 1800]} I want to replace the numbers in the first element of each sub-array with the corresponding ...

Do we always need to incorporate components in Vue.js, even if there are no plans for reuse?

I've been pondering this question for some time now: is it necessary for every component to be reusable? Consider a scenario where we have HTML, CSS, and JavaScript that cannot be reused. For instance, a CRUD table designed specifically for managing u ...

Troubleshooting Problem with Accordion Size in CSS

I am facing an issue with a dropdown menu that I have created. The dropdown has parent and child rows to display controls, but the width of the Accordion is not stretching as expected despite being set to 100%. Using Chrome and Edge developer tools, I insp ...