CSS3 transition events
W3C CSS Transitions Draft
The completion of a CSS Transition generates a corresponding DOM Event. An event is fired for each property that undergoes a transition. This allows a content developer to perform actions that synchronize with the completion of a transition.
Webkit
To determine when a transition completes, set a JavaScript event listener function for the DOM event that is sent at the end of a transition. The event is an instance of WebKitTransitionEvent, and its type is
webkitTransitionEnd
.
box.addEventListener( 'webkitTransitionEnd',
function( event ) { alert( "Finished transition!" ); }, false );
Mozilla
There is a single event that is fired when transitions complete. In Firefox, the event is
transitionend
, in Opera,oTransitionEnd
, and in WebKit it iswebkitTransitionEnd
.
Opera
There is one type of transition event
available. TheoTransitionEnd
event
occurs at the completion of the
transition.
Internet Explorer
The
transitionend
event occurs at the completion of the transition. If the transition is removed before completion, the event will not fire.
Stack Overflow: How do I normalize CSS3 Transition functions across browsers?
How to compose JS events and CSS transition timings?
The magic of transitionend
What you're looking for is to use the event listener transitionend
after adding the class with .classList.add
element.classList.add('yourTransitionAnimationClass')
element.addEventListener('transitionend', callbackFunction)
CSS transition on click event from another element
Display is not an animatable property. Try changing the form height or opacity. For example:
form {
-webkit-transition: opacity 1s;
transition: opacity 1s;
}
form.hidden {
opacity: 0;
}
Then just use JavaScript to toggle the class.
How to add CSS transition on closing event of a details tag?
You can substitute toggling .className
for details[close]
selector; at mouseover
event check if element is not .open
, if true
, set property to .open = true
at mouseout
event add .className
, use .one()
animationend
event to remove .className
and set .open
to false
at event handler.
$(function() { $("details").on({ mouseover: function() { if (!this.open && !$(this).is(".close")) $(this).prop("open", true) .one("animationend", function() { $(this).addClass("animationDone") }) }, mouseout: function _close() { if (!$(this).is(".close") && $(this).is(".animationDone")) $(this).addClass("close") .one("animationend", function() { $(this).prop("open", false) .removeClass("close animationDone") }) }, click: function(e) { e.preventDefault(); } })});
details[open] SUMMARY~* { animation: sweepin .5s ease-in-out;}
details.close SUMMARY~* { animation: sweepout .5s ease-in-out;}
@keyframes sweepin { 0% { opacity: 0; margin-left: -10px } 100% { opacity: 1; margin-left: 0px }}
@keyframes sweepout { 0% { opacity: 1; margin-left: 0px } 100% { opacity: 0; margin-left: -10px }}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><details> <summary>Here my little summary</summary> <p>... Do you want more details?</p> <p>Here have some details!</p></details>
Callback on CSS transition
I know that Safari implements a webkitTransitionEnd callback that you can attach directly to the element with the transition.
Their example (reformatted to multiple lines):
box.addEventListener(
'webkitTransitionEnd',
function( event ) {
alert( "Finished transition!" );
}, false );
CSS3 transition event Listener with jQuery
in jQuery you should use bind()
or on()
method:
$(this).parent().bind( 'transitionend', function() {alert("1"); });
Related Topics
How to Detect When a Page Exits Fullscreen
How to Get the Position of Text Within an Element
How to Make a Div Stick to the Top of the Screen Once It's Been Scrolled To
How to Remove a Style Added With .Css() Function
Equivalent of Jquery .Hide() to Set Visibility: Hidden
Trigger CSS Transition on Appended Element
Rails and Backbone Working Together
How to Upload Files Asynchronously With Jquery
Why Is Using the JavaScript Eval Function a Bad Idea
How to Check Connection Type (Wifi/Lan/Wwan) Using Html5/JavaScript
Add Content to a New Open Window
Stop an Input Field in a Form from Being Submitted
Changing CSS Pseudo-Element Styles Via JavaScript
Check If an Element'S Content Is Overflowing
How to Make the Browser Wait to Display the Page Until It's Fully Loaded
Force "Landscape" Orientation Mode
How to Decrypt Message With Cryptojs Aes. I Have a Working Ruby Example