当 div 上的转换结束并且所有 CHILD div 上的转换结束时,会触发 webkitTransitionEnd 事件吗?
总之,
我遇到的情况大致如下:
我的 HTML 页面 a 包含 div(我将其称为 “parentDiv”),我正在其上执行转换。当该转换结束时,它应该调用 "onTransitionEndParent",
parentDiv 包含一个 div(我将其称为 "childDiv"),我正在对它执行不同的操作 过渡。当该转换结束时,它应该调用“onTransitionEndChild”。
所以,我的代码大致如下:
parentDiv.addEventListener("webkitTransitionEnd", onTransitionEndParent, false);
childDiv.addEventListener("webkitTransitionEnd", onTransitionEndChild, false);
我发现的问题...
onTransitionEndParent 在parentDiv 的转换结束时被调用(正确)。然而,它ALSO在childDiv的转换结束时调用(不是我所期望的...)
换句话说...
- onTransitionEndChild在childDiv的转换结束时调用
- onTransitionEndParent在parentDiv的转换结束时调用 当 childDiv 的转换结束时再次
这是正确的行为,还是我做错了什么?
有没有办法确保 onTransitionEndParent 仅在 ParentDiv 的转换结束时调用,而不是在其任何子 div 的转换结束时调用?
非常感谢。
All,
I have a situation that looks roughly like this:
My HTML page a contains div (which I'll call "parentDiv") on which I'm performing a transition. When that transition ends, it should call "onTransitionEndParent"
parentDiv contains a div (which I'll call "childDiv") on which I'm performing a different transition. When that transition ends, it should call "onTransitionEndChild".
So, my code looks roughly like this:
parentDiv.addEventListener("webkitTransitionEnd", onTransitionEndParent, false);
childDiv.addEventListener("webkitTransitionEnd", onTransitionEndChild, false);
The problem I'm finding...
onTransitionEndParent is called when the parentDiv's transition ends (correct). However, it's ALSO called when childDiv's transition ends (not what I expected...)
In other words...
- onTransitionEndChild is called when childDiv's transition ends
- onTransitionEndParent is called when parentDiv's transition ends
AND AGAIN when childDiv's transition ends
Is this the correct behavior, or am I doing something wrong?
Is there a way to make sure that onTransitionEndParent is ONLY called when the parentDiv's transition ends, and NOT when any of it's child div's transitions end?
Many thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
transitionEnd
是所谓的冒泡事件,它从子级分派(冒泡)到其父级。您的选择:
event.target
属性 - 它应包含已结束转换的元素。
event.stopPropagation()
以防止其冒泡。transitionEnd
is so called bubbling event that is being dispatched (bubbles up) from child to its parents.Options for you:
event.target
property of the event object - itshould contain element with ended transition.
event.stopPropagation()
so to prevent its bubbling.要添加到 @c-smiles 答案,当元素上有多个转换时,检查 event.propertyName 会有所帮助。所以,举例来说——
To add to @c-smiles answer, checking for event.propertyName helps when there are multiple transitions on the element. So, for example -
上次 chrome 更新后我遇到了同样的问题。子动画触发了父动画的动画结束。这种情况仅发生在桌面版 Chrome 中,而不是 FF 或移动版 Chrome 中。
对于任何感兴趣的人,我通过使用以下方法解决了这个问题:
I encountered the same problem after the last chrome update. Children animations triggered animationend for the parent. This only happened in Chrome for desktop and not in FF or Chrome for mobile.
For anyone interested I solved this by using: