Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drag Project #11

Open
Preetiaarya opened this issue Nov 28, 2024 · 1 comment
Open

Drag Project #11

Preetiaarya opened this issue Nov 28, 2024 · 1 comment

Comments

@Preetiaarya
Copy link
Contributor

Preetiaarya commented Nov 28, 2024


Expected outcome :-----
user should be able to click on that div and move it into another div. Anytime user dragged div is on top of another div, the underlying div should change its background color. When the drag stops, if user div is within the boundary of any of the 5 divs, it should be moved inside the category div.

Steps to produce:-----
a. create div
b. change position of div
c. Made the Div drag able using mouse move and mouse down
d.create 5 new div in html
e.when I dragged div is on top of another div then change its background color but when stop drag then drag div take a fix position

Actual outcome: I want to set the position of drag Div when drag Div overlap category Div
drag-p

@dennyabrain
Copy link
Contributor

Expected Outcome

When a user finishes dragging the div, it should remain within the container div

Actual Outcome

When a user finishes dragging the div, it goes back to the original position at the top left of screen.

In your "mouseup" listener on line 43, you are supposed to set the position of the dragDiv. Your code looks like this

const centerX = currentDivRect.width / 2 - dragDiv.offsetWidth / 2;
const centerY = currentDivRect.height / 2 - dragDiv.offsetHeight / 2;

It should be something like this

const centerX = currentDivRect.left
const centerY = currentDivRect.top

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants