How would I use jQuery to determine when a CSS animation for an element has ended and then apply a new style to that element? Here is my non-functional code below.
$("#icon").jQuery.Event("webkitAnimationEnd", function(event){
('#icon').css('opacity', '1');
});
The animationend event occurs when a CSS animation has completed. For more information about CSS Animations, see our tutorial on CSS3 Animations. The numbers in the table specify the first browser version that fully supports the event. Numbers followed by "webkit" or "moz" specify the first version that worked with a prefix.
jQuery Animations - The animate() Method. The jQuery animate() method is used to create custom animations. Syntax: $(selector).animate({params},speed,callback); The required params parameter defines the CSS properties to be animated. The optional speed parameter specifies the duration of the effect.
A function that is called once the animation on an element is complete. The .animate () method allows us to create animation effects on any numeric CSS property. The only required parameter is a plain object of CSS properties.
transitionend and its related events are quite helpful when manipulating CSS transitions and animations using JavaScript. Changing a CSS animation from its current values can be done by obtaining the stylesheets in JavaScript, but can be quite involved. In JavaScript, CSS transitions are generally easier to work with than CSS animations.
I think actually what you are looking for is the .bind() method:
$("#icon").addClass('thisClassWillApplyMyCSSAnimation').bind('animationend webkitAnimationEnd MSAnimationEnd oAnimationEnd', function(e){
//DO WHATEV
$('#icon').css('opacity', '1');
});
You can use one()
$("#icon").one('animationend webkitAnimationEnd MSAnimationEnd oAnimationEnd', function(e) {
//Your css
$('#icon').css('opacity', '1');
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With