Giter Site home page Giter Site logo

blogs's People

Contributors

zhukejin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

blogs's Issues

事件流

事件传播三阶段:
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加载的过程中触发捕捉事件,而冒泡必须在加载完成后才会触发。这样理解就很好理解作者的实验项目了

blogs/JAVASCRIPT/Javascript-event.md的另一观点

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)

我的看法,这样理解才更加正确

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.