I’m trying to build a jQuery plugin that allows you to drag and draw a rectangle (or a div with a border) but I’m not sure how to do it. I don’t know of any that currently have this ability so I don’t know where to look for an example of how to do this.
How can I implement drag and draw in jQuery?
The basics for something like this are quite simple, when you think about it:
mousedownevents on some container (possible the entire document);eventobject (e.pageXande.pageY);mousemoveevents to change thewidthandheightobject (based on the mouse coordinates);mouseupevent to detach themousemoveevent listener.The aforementioned absolute placed element is, e.g., a
<div>with a border andbackground: transparent.Update: here is an example:
Demo: http://jsbin.com/ireqix/226/