简体   繁体   中英

How to get current position(X Y) of div that i am dragging around in react?

In my react project i would like to get current position of this div that i can drag around on screen. I mean current XY coordinates

I think you want to listen to is the Drag Event - take a look at the Mozilla Documentation for good examples

Remember in React the events will be referred to in camel case - onDragStart , onDragEnd , etc.

// A sample drag handler where you are getting the elements coordinates
function onDragStartHandler (ev) {
    var rect = ev.target.getBoundingClientRect();
    console.log(rect.top, rect.right, rect.bottom, rect.left);
}

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