What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Skype & Technology » Tech Talk » Drag and Drop Menu Problem

Drag and Drop Menu Problem
Author: Message:
-dt-
Scripting Contest Winner
*****

Avatar
;o

Posts: 1819
Reputation: 74
36 / Male / Flag
Joined: Mar 2004
RE: Drag and Drop Menu Problem
wtf you are you people on about its not that complex :-/

your element looks like this
<div id="moveme" style="position:absolute;left:0px;top:0px;background:blue;width:90px;height:90px;"></div>

you get the reference to that div by going
code:
var element = document.getElementById('moveme');
you add an event listener for mousemove
code:
document.addEventListener('mousemove',test,false);

you have another event listener for mouse down and mouse up
code:
document.addEventListener('mouseup',testOff,false);
element.addEventListener('mousedown',testOn,false);

then you have three functions which control this , one to turn it on , one to turn it off and one to move the element.
code:

var ismoving = false
var dx = 0;
var dy = 0;

function testOn (e){
ismoving = true;
//now you have to get the orginal click point
dx= e.clientX - parseInt(element.style.left);
dy= e.clientY - parseInt(element.style.top);
}

function testOff(e){
if(ismoving){
//this helps to stop that slight jumping when you release a drag then drag it again.
dx= e.pageX - parseInt(element.style.top);
dy= e.pageY - parseInt(element.style.left);
}
ismoving = false;
}

function test(e){
if(ismoving){
//minus the current mouse position from the orginal location.
var left= e.clientX-dx;
var top = e.clientY-dy;

//now we move the element.
element.style.left = left + 'px';
element.style.top = top + 'px';
}
}




thats the basic idea behind the dragging.  then you would save the location in the testOff function and get a php script or something to move the element back there when the page loads.

This post was edited on 02-01-2006 at 01:49 AM by -dt-.
[Image: dt2.0v2.png]      Happy Birthday, WDZ
02-01-2006 01:49 AM
Profile PM Web Find Quote Report
« Next Oldest Return to Top Next Newest »

Messages In This Thread
Drag and Drop Menu Problem - by michael_m91 on 01-30-2006 at 07:03 PM
RE: Drag and Drop Menu Problem - by Supersonicdarky on 01-30-2006 at 10:34 PM
RE: Drag and Drop Menu Problem - by Supersonicdarky on 01-30-2006 at 10:43 PM
RE: Drag and Drop Menu Problem - by michael_m91 on 01-30-2006 at 10:56 PM
RE: Drag and Drop Menu Problem - by RaceProUK on 01-31-2006 at 01:15 AM
RE: Drag and Drop Menu Problem - by ShawnZ on 01-31-2006 at 02:21 AM
RE: Drag and Drop Menu Problem - by michael_m91 on 01-31-2006 at 03:04 AM
RE: Drag and Drop Menu Problem - by ShawnZ on 01-31-2006 at 03:20 AM
RE: Drag and Drop Menu Problem - by rav0 on 01-31-2006 at 07:14 AM
RE: Drag and Drop Menu Problem - by michael_m91 on 01-31-2006 at 10:25 PM
RE: Drag and Drop Menu Problem - by Supersonicdarky on 01-31-2006 at 10:26 PM
RE: Drag and Drop Menu Problem - by michael_m91 on 02-01-2006 at 12:06 AM
RE: Drag and Drop Menu Problem - by RaceProUK on 02-01-2006 at 12:24 AM
RE: Drag and Drop Menu Problem - by michael_m91 on 02-01-2006 at 12:45 AM
RE: Drag and Drop Menu Problem - by -dt- on 02-01-2006 at 01:49 AM


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On