I want to achieve a draggable element in vanilla javascript. I want to make a small circular div draggable within a square div.
To make myself a bit more clear, I do NOT want to:
- Create drag and drop,
- Use jQuery UI or any other library or plugin to achieve this, just vanilla javascript
I already have a few events for handling dragging:
parent.addEventListener("mousedown", ..),
document.addEventListener("mouseup", ..)
and
document.addEventListener("mousemove", ..)
My question is how can I keep the draggable inside the given bounds of its parent?
