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 opting for left: and top: properties instead, I started making progress. I incorporated faster/slower buttons to adjust the animation speed by changing the seconds property inline. While this functioned well in Chrome, it did not work in IE.

To demonstrate, setting the initial animation style inline is achieved like so:

var speed = 1.5;
var animationCSS = 'myfirst '+speed+'s';

$('#button1').click(function () {
    alert("Set initial speed");

    $('#test')
        .css('background-color', '#000')
        .css('animation', animationCSS)
        .css('-webkit-animation', animationCSS); 
});

Using jQuery, I dynamically assign the animation CSS with a custom speed and have another button that changes the speed variable and reassigns the CSS. The animation should run again as a new inline style has been applied. This functions correctly in Chrome but not in IE10. I also have a removeCss function that seems to be working fine - it works in Chrome regardless of whether this line is included or not.

$('#button2').click(function () {
    alert("Slow down and change speed");
    
    $('#test').removeCss('animation,-webkit-animation,
    speed = 10;
    animationCSS = 'myfirst '+speed+'s';
    $('#test').css('background-color', '#00FFFF')
        .css('animation', animationCSS)
       .css('-webkit-animation', animationCSS);
});

This issue is frustrating me. When inspecting the elements, I can see that the new speed variable has been applied inline, but there is no visible change taking place. Any suggestions?

Answer №1

From what I gather, the animation will only respond if you modify the value of animation-name. An efficient solution would be to link an animationEnd event to the element and specify this.style.animationName = ""; in that function. Subsequently, when you assign a new animation to it, it should function properly.

Answer №2

To enhance your web design, consider creating an animation called mysecond with identical keyframes. Rotate between the animation names myfirst and mysecond to adjust the speed of the animation. This will prompt the animation to refresh. Another option is to establish multiple classes for various animations with distinct names and execution speeds and assign the appropriate class accordingly.

Check out the jsfiddle example: http://jsfiddle.net/AxQQB/11/

If you desire a seamless transition between animations, listen for the animationiteration event and update the class during that moment.

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

Tips for aligning an element vertically when it has a float using CSS or JavaScript

I am struggling with centering the image within the article list loop I created. The code snippet looks like this: <article class="article <?php if($i%2==0) { echo 'even'; } else { echo 'odd'; } ?>"> <section class ...

The CORS header 'Access-Control-Allow-Origin' is nowhere to be found

When I try to call this function from my asp.net form, I encounter the following error in the Firebug console while attempting to make an ajax request: Cross-Origin Request Blocked: The Same Origin Policy prevents me from accessing the remote resource lo ...

Combining two different text alignments within a single paragraph

I need to craft a paragraph with specific alignment requirements: 1st line: align:center 2nd line: align:left 3rd line: align:center 4th line: align:left The alignment should follow this pattern. Is there a CSS method for achieving this? ...

The sidebar is refusing to stick. I've exhausted all resources on Stack Overflow trying to fix it

Having issues with the sticky sidebar on my website, I've tried solutions from various Stack Overflow threads: Understanding "position: sticky;" property Fix for position:sticky not working Implementing sticky sidebar when scrolling down/up The is ...

Utilizing the jQuery plugin 'cookie' to retain the current tab selection on a webpage

Is it possible to provide a detailed explanation on how I can utilize the jQuery Cookie plugin to maintain the selected tab throughout my entire website? Here is the current JavaScript code in JSFiddle format: http://jsfiddle.net/mcgarriers/RXkyC/ Even i ...

Aligning text and lists using Bootstrap on both desktop and mobile devices

I want to format a text with a list similar to the images provided https://i.stack.imgur.com/6giDH.png for desktop and tablet view, but for mobile display I would like it to look like this https://i.stack.imgur.com/7zSXi.png This is my current approach ...

Click on a link to open it in the current window and simultaneously in a new window or tab

Is it possible to use jQuery to open a link in the current window and a second link in a new tab? Just to clarify, this is not an annoying pop-under. This request comes directly from the client for their company's system. Here is what I've been ...

`How can I update the background image of a div element?`

Greetings and well wishes to everyone. Essentially, I have a div that looks like this: <div class="divele" style="background: url("/image/bkimg.jpg") top center no-repeat;background-size:cover;"></div> Next, there is an upload button where t ...

Variety of background colors for different categories

Is there a way to showcase my categories with different background colors using a custom post type? I want to link the slug name from my taxonomy to serve as the class attribute for a span element and style it with CSS. However, I am encountering issues wi ...

Guide to performing an Ajax call on click event to a PHP file using jQuery

I have a hyperlink directing to domain.com. When someone clicks on it, I want an ajax call to be made to counter.php with 2 variables posted, in order to increase the views for that link by 1. Here is the hyperlink: <a href="http://www.domain.com" onC ...

Is there a way to create an infinite fade in/out effect for this?

Is there a way to ensure that the method runs after the "click" event in this code snippet? The code currently fades in and out the div #shape while the start variable is true, but when I call the "start" method from the "click" event, the browser stops wo ...

One way to dynamically retrieve the ID of a jQuery tab using a foreach loop in PHP OOP

I have a category table and subcategory table in my database. Currently, I am attempting to showcase the "category" title as the tab and the corresponding "subcategory" name as the content within the tab. Despite searching for a solution on Google, I was ...

JavaScript counter unexpectedly resetting to zero instead of the specified value

After gathering feedback from voters: My current issue revolves around a Java counter I created. Ideally, the numbers should start at 0 and increment to the specified number upon page load. You can see an example of this functionality here: https://codepe ...

Concealing a button once the collapse feature is toggled in Bootstrap

The following code snippet from the bootstrap website demonstrates how to use collapse functionality: <a class="btn btn-primary" data-toggle="collapse" href="#collapseExample" aria-expanded="false" aria-controls="collapseExample"> Link with href & ...

The problem arose when the jquery onchange event was not triggered after dynamically inserting a

Here is my current setup: somefile.php $("document").ready(function() { var handler = function(data) { var JsDiv = document.getElementById("somediv"); JsDiv.innerHTML = data; }; $("input[type='checkbox']").change( function() ...

Customize button appearance within mat-menu in Angular versions 2 and above

Is there a way to style my mat-menu to function similar to a modal dialog? I am having difficulty with the styling aspect and need advice on how to move the save and reset buttons to the right while creating space between them. I have attempted to apply st ...

Creating a recursive setTimeout loop using Coffeescript

I am currently developing a live photo stream application. The idea is that users will be able to upload photos to a specific folder on my server via FTP, and the app should automatically update whenever a new photo is added, without needing to refresh the ...

Best practices for arranging several divs with CSS

I am in the process of creating a main header for several web pages I'm working on. The layout I have in mind includes an image, centered text below the image (all to the left of the main header), a main header that I want to be in the center of the p ...

Performing multiple service calls in a synchronized way using Ajax

Currently, I am working on a project where I need to make multiple REST service calls to accomplish the required functionality. Furthermore, in order to complete this task, I have to use the response from ServiceCall-ONE as the input for ServiceCall-TWO. S ...

Center text vertically within an HTML Bootstrap row

I am creating a Bootstrap row with three columns - col-sm-2, col-sm-8, and col-sm-2. In the first column, I plan to insert a card, in the second column some text, and in the third column a tooltip. This row will be repeated multiple times. As a beginner ...