views:

435

answers:

3

Hello

I have a div for which i have set the cursor:move style. The div shows up as a modal popup window. I would like to let the user move the div around.

<style>
.popup{cursor:move;position: absolute; width: 100%; height: 100%; top: 0; left: 0; margin:auto;}
</style>

<div id="modaldiv" style="popup">
   content goes here
</div>

Any help is greatly appreciated.

Thanks.

A: 

You might want to look at http://dynamicdrive.com/dynamicindex8/dhtmlwindow/index.htm
or
http://dynamicdrive.com/dynamicindex8/dhtmlwindow/dhtmlmodal.htm

thephpdeveloper
Thank. I will try that.
Murali Bala
Err... that script is last changed on '07, tested on "FF1+ IE6+ Opera 8+" and doesn't seem to be unit tested either. The code is rather suspicious: relies on sniffing, doesn't believe in semicolons, does rather poor XHR abstraction, etc.
kangax
but that's something (s)he can start on. that's something we call life before jQuery.
thephpdeveloper
+1  A: 

If you need the basic idea then it will be like this.

  1. A flag should be set when the mousedown occurs.

  2. If the flag is set and mousemove occurs then change the position of the div according to the mouse position.

  3. Unset the flag when mouseup occurs.

From this I don't think it is much harder to develop one.

If you need one based on a framework then this one will help you. Using jQuery

Draggable

$("#modaldiv").draggable();

will make the div draggable.

rahul
You think it's really sexy using jquery+jqueryui to implement dragndrop :) ?
Mushex Antaranian
Why not? If you have a feature that deals with cross browser issues and best DOM traversal methods then go for it.
rahul
A: 

this should work http://www.dynamicdrive.com/dynamicindex11/domdrag/index.htm i think this is what you want to do :-?

DanTdr