CSS3 过渡事件
元素是否会触发任何事件来检查 css3 转换是否已开始或结束?
Are there any events fired by an element to check whether a css3 transition has started or end?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
W3C CSS 过渡草案
Webkit
Mozilla
歌剧
Internet Explorer
Stack Overflow:如何跨浏览器标准化 CSS3 转换函数?< /a>
W3C CSS Transitions Draft
Webkit
Mozilla
Opera
Internet Explorer
Stack Overflow: How do I normalize CSS3 Transition functions across browsers?
更新
所有现代浏览器现在都支持无前缀事件:
element.addEventListener('transitionend', callback, false);
https://caniuse.com/#feat=css-transitions
我正在使用 Pete 给出的方法,但是我现在开始使用以下
替代方法你使用 bootstrap 那么你可以简单地这样做
这是因为它们在 bootstrap.js 中包含以下内容
请注意,它们还包含一个 emulateTransitionEnd 函数,可能需要该函数来确保回调始终发生。
http://blog.alexmaccaw.com/css-transitions
Update
All modern browsers now support the unprefixed event:
element.addEventListener('transitionend', callback, false);
https://caniuse.com/#feat=css-transitions
I was using the approach given by Pete, however I have now started using the following
Alternatively if you use bootstrap then you can simply do
This is becuase they include the following in bootstrap.js
Note they also include an emulateTransitionEnd function which may be needed to ensure a callback always occurs.
http://blog.alexmaccaw.com/css-transitions
所有现代浏览器现在都支持无前缀事件:
element.addEventListener('transitionend', callback, false);
适用于最新版本的 Chrome、Firefox 和 Safari。即使是IE10+。
All modern browsers now support the unprefixed event:
element.addEventListener('transitionend', callback, false);
Works in the latest versions of Chrome, Firefox and Safari. Even IE10+.
在 Opera 12 中,当您使用纯 JavaScript 进行绑定时,“oTransitionEnd”将起作用:
但是,如果您通过 jQuery 绑定,则需要使用“otransitionend”。
如果您使用的是 Modernizr 或 bootstrap-transition.js,您只需进行更改即可:
您还可以在这里找到一些信息 http: //www.ianlunn.co.uk/blog/articles/opera-12-otransitionend-bugs-and-workarounds/
In Opera 12 when you bind using the plain JavaScript, 'oTransitionEnd' will work:
however if you bind through jQuery, you need to use 'otransitionend'
In case you are using Modernizr or bootstrap-transition.js you can simply do a change:
You can find some info here as well http://www.ianlunn.co.uk/blog/articles/opera-12-otransitionend-bugs-and-workarounds/
只是为了好玩,不要这样做!
Just for fun, don't do this!
如果您只想检测单个转换结束,而不使用任何 JS 框架,这里有一个方便的实用函数:
用法:
那么如果您希望在某个时刻取消,您仍然可以使用它来完成它
对于其他事件用法也有好处: )
If you simply want to detect only a single transition end, without using any JS framework here's a little convenient utility function:
Usage:
then if you wish to cancel at some point you can still do it with
It's good for other event usages as well :)