View Full Version : Draggable Layers?

12-31-2002, 12:48 PM
I'm trying to emulate a windows desktop environment on a web page, and i'm a little bit stuck.

I want to be able to have draggable "psuedo-window" layers.

I've been able to find a few draggable layer scripts and draggable image scripts but havent come up with the right modifications for what i need.

I want to be able to click and drag a certain element contained within a layer, which will then drag the entire layer. This, to emulate the draggability property of the title bar of a 'windows' window.

Can anyone help me out, please?


Mr J
12-31-2002, 12:55 PM
Is this any good?

<SCRIPT language=JavaScript1.2>
moving2 = false;

function Dragnow2(){
if(event.srcElement.className!="dragme") return; // Only move "dragme" objects
X_offset=event.clientX-event.srcElement.style.pixelLeft; // differnce between the obj pos and cursor pos X
Y_offset=event.clientY-event.srcElement.style.pixelTop; // differnce between the obj pos and cursor pos Y

function Moveto2(){
if(!moving2) return true;
if(event.button!=1) return true;
obj.style.pixelLeft=event.clientX-X_offset; // new position X
obj.style.pixelTop=event.clientY-Y_offset; // new position Y
return false;

document.onmouseup=new Function("moving2=false");
// -->

<DIV class="dragme" style="position:absolute;top:0;left:0;cursor:hand;border:2 solid red">Hello World</DIV>

<DIV class="dragme" style="position:absolute;top:100;left:0;cursor:hand;border:2 solid blue">Hello World</DIV>

12-31-2002, 01:34 PM
Not exactly what i'm looking for. I could probably figure it out from that code if i wasnt retarded, but this is what i need.


1 & 2 = the entire layer
1 = object, image, or SOMETHING on the layer
2 = the rest of the layer

By clicking and dragging '1' I want to be able to drag the entire layer (1 and 2)

Clicking and dragging should not work in the '2' area.

Like how the window yer reading this in works.

Mr J
12-31-2002, 07:58 PM
Got ya ...

Here's one I put on the shelf a while back.

Still needs a bit of attention maybe but see if it will do you.

12-31-2002, 08:38 PM
Something I had done a long time ago as a proof of concept. I don't think the binding for Mozilla works anymore, but it shouldn't be too hard to update to post-1.0 XBL...

12-31-2002, 08:46 PM
has exactly the program you looking for..



12-31-2002, 09:33 PM
Thanks everyone! I love you like a pregnant woman loves pickles in her icecream! :D