This is a small example implementing click-to-drag with a bit of JavaScript…Please let us know if you have any questions!
- Watch the short screencast associated with this sketch here
- Check out another gist of ours on mouse events here
- Modify the code so that:
- …if you double-click the square, it disappears
- …when you release the square, its
innerHTML
is replaced with itsx
- andy
-coordinates - …if you click and drag within a certain distance of another div, the dragged
div
'clicks' into place— i.e. if you drag it within a certain square and let go, it always ends up in the center of that square