I found the transition end events, but I need a transition start event. Is there such thing?
-
Nope, at least not yet.Frédéric Hamidi– Frédéric Hamidi2014-01-19 15:59:29 +00:00Commented Jan 19, 2014 at 15:59
-
Why would you need it, shouldn't you know when you start a transition ?adeneo– adeneo2014-01-19 15:59:57 +00:00Commented Jan 19, 2014 at 15:59
-
1@adeneo, mainly for other modules reacting on transitions initiated elsewhere. That would be nice to have :)Frédéric Hamidi– Frédéric Hamidi2014-01-19 16:01:22 +00:00Commented Jan 19, 2014 at 16:01
-
1@adeneo: Not always does a property change really start a transition - you would need additional logic to test whether one expects a transition.Bergi– Bergi2014-01-19 17:38:42 +00:00Commented Jan 19, 2014 at 17:38
2 Answers
No, not yet. (reiterating @Frédéric Hamidi's comment.)
Consider broadcasting your own event with an event aggregator, mediator, or pub/sub. These all mean basically the same thing: Instead of waiting for JavaScript's DOM/CSS event specs to catch up with your needs, make your own global/near-global event management system, or use custom events in whatever event framework you're already using.
For example, you can use custom jQuery events:
// Transition target (body, for example)
var $body = jQuery(document.body);
// Register our transition starting function (left as exercise)
$body.on('transition_start', startFunction);
// Start the transition...
$body.addClass('transitioning')
// ... and let everyone know
.trigger('transition_start');`
6 Comments
function startFunction(){$body.addClass('transitioning');} $body.trigger('transition_start');$body.addClass('transitioning') is called, using your code it is unnecessary to trigger an event to start the transition because is has already been started. Instead with my refactoring suggestion you can trigger the event exactly to start the transition.UPDATE: transitionstart and transitioncancel are both in the CSS Transitions 2 specification, being developed currently in Editor's Draft status.
If you didn't know, transitionstart is implemented in Internet Explorer 10 and above. It's not in any spec and is thus a non-standard feature. It's unprefixed and generally safe to use, I'd assume, since this is how it would be implemented when (or if) arriving in a spec - so maybe you could do a conditional like this:
if ("transitionstart" in window) {
object.addEventListener("transitionstart", function() {
// IE 10 + and Edge
});
}
else {
// fallback
}
The only kind of "discussion" I could find regarding the issue is this mail sent to the W3C by @Daniel Trebbien, asking about the possibility for including new transition events like transitionstart and transitioncancel into the spec. He hasn't even got a reply from someone, that's really sad.