简体   繁体   中英

How to trigger a custom event in capture phase

Is there a way to trigger a custom event in javascript, so that it will propagate using the capture model?

I have a hierarchy of elements that I use as a mean to communicate between objects. Each level of the hierarchy represents a sub-family of object. Ideally, I could trigger an event to each family's or sub-family's objects using their common ancestor.

eg:

animals |_ | mammals | |_cats | |_dogs |_ reptiles |_alligators |_dinosaurs

(please no comments on my inadequate taxonomy :) )

I would like to be able to trigger an event for all animals, all mammals or all cats, or event to a single cat instance.

However, I can only find examples of custom events using the bubbling phase, so I want to know if it's me missing something or is this really impossible.

I know I can use event delegation on the root element for all instance, but it will scale really badly (this system needs to handle thousands of events of all types).

Any ideas?

对于当前的DOM事件规范,这是不可能的,因为它仅支持冒泡阶段。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM