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 ha
The basics for something like this are quite simple, when you think about it:
mousedown
events on some container (possible the entire document);
event
object (e.pageX
and e.pageY
);mousemove
events to change the width
and height
object (based on the mouse coordinates);mouseup
event to detach the mousemove
event listener.The aforementioned absolute placed element is, e.g., a Update: here is an example: Demo: http://jsbin.com/ireqix/226/background: transparent
.
$(function() {
var $container = $('#container');
var $selection = $('