简体   繁体   中英

Drag & drop with react

I'm using react-draggable to implement drag and drop feature.

I have to drag a component (A) inside another (B): how can I get final A position related to B?

calculate the position of each related to the screen and compare

const aRect = a.getBoundingClientRect();
const bRect = b.getBoundingClientRect();

if(aRect.right > bRect.right) {
    // a start after b
}
if(aRect.top > bRect.top) {
   // a start under b
}

// etc.

you can get the position of the componet A by getting the transform and translate property using document.getElementById('') and get the transform and translate. you need to make a function which will be fetching the css onDrag for the draggable.

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