Javascript:是否有 CSS 过渡开始事件?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21219025/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Javascript: Is there a CSS transition start event?
提问by barakuda28
I found the transition end events, but I need a transition start event. Is there such thing?
我找到了过渡结束事件,但我需要一个过渡开始事件。有这种事吗?
回答by Reed Spool
No, not yet. (reiterating @Frédéric Hamidi's comment.)
还没有。(重申@Frédéric Hamidi 的评论。)
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.
考虑使用事件聚合器、调解器或发布/订阅广播您自己的事件。这些都意味着基本相同的事情:与其等待 JavaScript 的 DOM/CSS 事件规范来满足您的需求,不如创建您自己的全局/近乎全局的事件管理系统,或者在您已经使用的任何事件框架中使用自定义事件.
For example, you can use custom jQuery events:
例如,您可以使用自定义 jQuery 事件:
// 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');`
回答by mnsth
UPDATE:transitionstart
and transitioncancel
are both in the CSS Transitions 2 specification, being developed currently in Editor's Draft status.
更新:transitionstart
并且transitioncancel
都在CSS Transitions 2 规范中,目前正在开发中处于编辑器的草稿状态。
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:
如果您不知道,它transitionstart
是在 Internet Explorer 10 及更高版本中实现的。它不在任何规范中,因此是非标准功能。我假设它是无前缀的并且通常可以安全使用,因为这是在(或如果)到达规范时将如何实现 - 所以也许你可以做这样的条件:
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 thismail 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.
唯一的一种“讨论”我能找到关于这个问题是该邮件由@Daniel Trebbien发送到W3C,询问了包括新的过渡活动,如可能性transitionstart
,并transitioncancel
进入规范。他甚至没有得到任何人的答复,这真是令人难过。