views:

265

answers:

2

Hi,

I want to be able to create a div in my application by clicking and dragging. Clicking would initiate the div creation, while dragging would resize the div.

I have seen similar functionality in several jquery calendar plugins, I want to be able to do it in my application too.

Can anyone please guide me into the right direction? Any jQuery plugin or something that I am missing?

Thanking you for your help.

+3  A: 

You could following this plan:

When the mouse button goes down, you record the x/y values. When it comes up, you record the new x/y values. Subtract the first from the latter; if the result is not negative, create a div with those dimensions.

Jonathan Sampson
Alternatively, if the result is negative, use left = min(x1,x2) height = abs(x1-x2)
Jimmy
Thank you for your suggestion, I think I wasn't clear enough though. I am actually creating a calendar sorts of application. So I have to create an appointment from click and drag. The problem is that I have a grid of equal sized divs in my screen, what I want is to be able to create a div by click and drag but its dimensions would be a multiple of the grid divs.If it were purely click and drag and create it would not be such a problem.
Dhruva Sagar
+2  A: 

Don't reinvent the wheel: http://plugins.jquery.com/project/Plugins/category/45

Andreas Bonini
Hi, thank you for your time and reply, I have actually come across this while searching on jquery, but I am not very sure how this cam help in what I want to achieve. I'll have a look at the examples. Thank You.
Dhruva Sagar
I am not able to take the help from any particular plugin to achieve what I want. As you can read from the comment on the previous answer, my requirements are a bit specific and quite different, however I have now found a hacky work around the same and am experiementing with it trying to now disallow user to be able to create divs overlapping with other divs, I am sure I will get it in a few days.Thanks for your help though :)
Dhruva Sagar