I would like to create div
element which behaves similar to clicking and dragging on Windows desktop.
So far I my code does the following:
- We create (just changing CSS styling of display:none to display:block) a `div` when the page detects a mousedown
- If the user moves the mouse while still mousing down, they modify the size of the div.
- When the user releases the mouse button, we hide the div (display:none)
My problem is the resize part. Right now, the div can be expanded in a South East direction only.
Refer to this Fiddle an example.
Play around with the Fiddle example to see what I mean (you cannot expand vertically beyond origin, for example).
The reason, I assume, is becuase newX
and newY
are negative values. How can I solve this?