zhukejin / blogs Goto Github PK
View Code? Open in Web Editor NEWblogs
Home Page: http://zhukejin.com
blogs
Home Page: http://zhukejin.com
事件传播三阶段:
1.capture phase (事件捕获)
2.target phase (处于目标)
3.bubbling phase (事件冒泡)
在 target phase,event handler 被调用的顺序不再遵循先捕获,后冒泡的原则,而是严格按照 event handler 注册的顺序,先注册,故而先执行。要改变二者的执行顺序,只需要改变两段源码的顺序即可。
W3C 规范:
Next, the implementation must determine the current target's candidate event listeners. This must be the list of all event listeners that have been registered on the current target in their order of registration. [HTML5] defines the ordering of listeners registered through event handler attributes. Once determined, the candidate event listeners must not be changed. Adding or removing listeners does not affect the current target's candidate event listeners.
https://stackoverflow.com/questions/18103391/usecapture-in-addeventlistener-behaves-strangely?lq=1
https://stackoverflow.com/questions/11841330/event-listeners-registered-for-capturing-phase-not-triggered-before-bubbling-w
捕捉是dom元素向后代下沉的过程,冒泡是相反,因此,捕捉和dom的加载顺序是一直的,在dom加载的过程中触发捕捉事件,而冒泡必须在加载完成后才会触发。这样理解就很好理解作者的实验项目了
window (1) -> document (1) -> body (1) -> ul (1) -> li -> ul (2) -> body (2) -> document (2) -> window (2)
在浏览器支持addEventListener的前提下
addEventListener(ul, function(){}, true)
// 这里的ul, 是 ul(1)
addEventListener(ul, function(){}, false)
// 这里的ul, 是 ul(2)我的看法,这样理解才更加正确
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.