27

I found the transition end events, but I need a transition start event. Is there such thing?

4
  • Nope, at least not yet. Commented Jan 19, 2014 at 15:59
  • Why would you need it, shouldn't you know when you start a transition ? Commented Jan 19, 2014 at 15:59
  • 1
    @adeneo, mainly for other modules reacting on transitions initiated elsewhere. That would be nice to have :) Commented 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. Commented Jan 19, 2014 at 17:38

2 Answers 2

13

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');`
Sign up to request clarification or add additional context in comments.

6 Comments

Well that's a bit radical to remove the question if this didn't help. It wouldn't exactly help me, if I was in OP shoes and the question got already answered in comments anyway
You are right @durrrr that was not right of me, deleted
Good hint thanks. But if I have to play a transition on the body I would refactor like this: function startFunction(){$body.addClass('transitioning');} $body.trigger('transition_start');
@salvolds can you expand on why?
Sure. Considering that the transition will start immediatly after $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.
|
9

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.

3 Comments

It seems that IE10 is the only browser that supports it at this time: developer.mozilla.org/en-US/docs/Web/Events/transitionstart
@iX3 Yes, IE 10, IE 11 and Microsoft Edge supports it as of now.
Apparently It's available in FF 53, but not in Chrome 60

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.