admin管理员组文章数量:1221774
In React js to every drag event there is a corresponding event with "capture" prefix onDragEnter vs onDragEnterCapture, onDragLeave vs onDragLeaveCapture and so on. Could any one tell difference between those and when to use which? They both repond to similar events.
In React js to every drag event there is a corresponding event with "capture" prefix onDragEnter vs onDragEnterCapture, onDragLeave vs onDragLeaveCapture and so on. Could any one tell difference between those and when to use which? They both repond to similar events.
Share Improve this question edited May 17, 2021 at 8:27 mikemaccana 123k110 gold badges427 silver badges531 bronze badges asked Nov 26, 2019 at 8:56 kunal vermakunal verma 4865 silver badges15 bronze badges 2- @RameshRajendran i am drying to create something with drag drop and when i see the events available for drag to every drag event i get a corresponding event with Capture prefix... – kunal verma Commented Nov 26, 2019 at 9:16
- @RameshRajendran like both onDragEnter and onDragEnterCapture are available – kunal verma Commented Nov 26, 2019 at 9:17
1 Answer
Reset to default 21Basically Bubbling and Capturing are two ways of event propagation.
Bubbling :
When an event happens on an element, it first runs the handlers on it, then on its parent, then all the way up on other ancestors.
Let’s say we have 3 nested elements form> div> p
with a handler on each of them:
A click on the inner <p>
first runs onclick:
- On that
<p>
. - Then on the outer
<div>
. - Then on the outer
<form>
. - And so on upwards till the document object.
Capturing : The event is first captured by the outermost element and propagated to the inner elements:
So in the same example when you click the outer element <form>
it runs on :
- on that
<form>
- then the inner
<div>
- then
<p>
While using react, to register an event handler for the capture phase, append Capture to the event name; for example, instead of using onClick, you would use onClickCapture to handle the click event in the capture phase.
The same goes for the other events.
Source [1] [2]
本文标签: javascriptReact JS onDragCapture vs onDragStack Overflow
版权声明:本文标题:javascript - React JS onDragCapture vs onDrag - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1739274384a2155956.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论