View Full Version : Action On MouseUp (Drag And Drop)

06-19-2010, 03:00 AM
Okay I Don't Know Much About Javascript, But I Need A Hand
I Have A Drag And Drop Script Along With A Simple Script To Make Things Appear And Disappear Bt Using This Line: ShowHide('Table'); return false;
I Want to Make It So That When I Drag Something over a Div, More Preferably a Table or an Image and Then Let Go of Your Mouse (onMouseUp) It Makes the Object Disappear Or Have An Action Happen


Alright, I wrote this a while ago and This Time I'll Be More Clear And Simple.
I Want To Make It So That If A Div Hovers Over A Table By Drag And Drop And You Drop Your Div in The Table An Action happens

06-19-2010, 05:53 AM
Well, in the onMouseUp event you're going to have to figure out if the mouse coordinates are within the boundaries of an element that you care about...

So if you have only one object, say a trash can, then just get the mouse coords and the left, top, width, height values of the trash can and determine if the mouse was inside that (at the time of the onMouseUp event).

If you have multiple elements that you can drop objects onto: Make an array of all the objects. In onMouseUp you get the mouse coords and then loop through your array of all objects, getting the left, top, width, height of each one and detecting if the mouse is inside one of them... then depending on which element it is you can perform the action associated with dropping it on that element (probably store that as your own function on each element).

Hopefully that makes some sense... though it might not if you aren't familiar with javascript.

This problem isn't exactly trivial unless you have programming experience and a bit of experience with Javascript.

Good luck.

06-19-2010, 06:02 AM
For The Most Part I Can Insert It in An HTML, Pretty Sad Considering How I'm In A Javascript Fourm.
So Here Is My sad sad Attempt,

//The coordinates Code
onMouseUp="function(){ShowHide('Table');return false;"}
how was it?
anyways could you give me the code for the coordinates?

P.S. ah yes! Sooo Useful Thanx Man! Pretty much A Trash Can Was What I Was Aiming For, Thanx

06-19-2010, 06:12 AM
PM me tomorrow and I might have time to give you a bit of code... but honestly I'm not going to build the whole thing for you. Start learning about the DOM and how to get values like offsetwidth/height absoluteleft/top. At that point you'll probably be able to write the code yourself. Well probly not, but you might be able to work with the bit of code I'll give you tomorrow.


06-19-2010, 06:30 AM
got it