TransitionEnd侦听器触发子元素 [英] TransitionEnd listener firing on child elements
问题描述
我在 div
中添加了一个 transitionend
事件监听器。这个 div
有些孩子在一些元素上有过渡。我希望transitionend事件只针对我添加它的元素触发,这是一个错误吗?或预期的行为?如果只是我添加了监听器的那个,它如何才能触发?
I added a transitionend
event listener to a div
. This div
has children who have transition on some elements. I want the transitionend event to only fire for the element I added it for, is this a bug? or expected behavior? How to make it fire only if its the one i added the listener to?
推荐答案
默认情况下冒泡的事件,
意味着它们将被传送到父元素,直到它们到达正文或处理器将停止它们。
Events are bubbling by default, meaning that they will be "transmitted" to the parent element until they hit the body or a handler that will stop them.
你可以:
- 按事件的目标确定它是您要定位的元素。
- 收听关于子项的事件和
event.stopPropagation()
。这样,他们就不会再通过父母了。
- Filter by the event's target being sure it's the element you're targetting.
- Listening to the event on children and
event.stopPropagation()
on them. That way, they won't bubble through the parent anymore.
如果您向我们展示一些代码,那么它会更容易根据您当前的实施情况,帮助您。
If you'd show us some code, it would be easier to help you, depending on your current implementation.
这篇关于TransitionEnd侦听器触发子元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!