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

Feature Request: recomputeBounds.resize #137

Open
aspiringLich opened this issue Dec 10, 2023 · 1 comment
Open

Feature Request: recomputeBounds.resize #137

aspiringLich opened this issue Dec 10, 2023 · 1 comment

Comments

@aspiringLich
Copy link

Adding an option to recompute the bounds when the bounding element is resized would be helpful for keeping draggable's in-frame when the browser window is resized.

I tried to implement this feature myself but couldn't figure it out (the box just kind of bugs out no matter what I try). Maybe someone more familiar with the library can give it a shot.

https://github.com/PuruVJ/neodrag/compare/6965d57..aspiringLich:main

@LiddellHunter
Copy link

I got around this by recomputing the position of the element myself. When the window is resized, check if the x position of the element plus its pixel width is greater than the viewport width. If it is, set the elements position.x -= the pixel count that is out of bounds.
For example:
windowWidth = 1000px;
element.posX = 950px;
element.boundingClientRect().offsetWidth = 100px;
(Out of bounds by 50px)

if("element width > windowWidth")
element.posX -= ( element.boundingClientRect().offsetWidth + element.posX ) - windowWidth;

element.posX is now 900px;

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