29/06/08 UPDATE: Handler feature added! Finally I decided to add a little piece of extra functionality to the EasyDrag plugin. It has been constantly requested, so now you can download and test it. I will be releasing it as a final version after some feedback, so please let me know if it works for you.
How does it work?
It’s very simple, first you call the easydrag() method as in the old version and then you call the setHandler() method passing to it the id of the element that will act as the handle. The handle MUST be a child element of the content that will be dragged.
$("#box2").easydrag(); $("#box2").setHandler('handler3');Files
It has been a while since my last post, mainly because I’m currently a little busy with some projects. In one of these projects I had to add a drag-and-drop behavior to some DOM elements, and for that I have created the EasyDrag jQuery plug-in that I’ll share with you now.
Its main purpose is to add the ability to drag and drop almost any DOM element without much effort. So it’s simple to use and you can also attach handlers both to the drag and to the drop events, which permits you to extend the basic functionality to whatever you need.
To be able to use this plugin you should set the element you want to drag as absolute positioned and set an unique id for it (although it’s not strictly necessary because the script will try to set both for use otherwise). You are also advised to set the size of the element. Finally you need to add a code similar to the following example into your page.
<script src="jquery.easydrag.js" type="text/javascript"></script> <script type="text/javascript"> $(function(){ // add drag and drop functionality to #box1 $("#box1").easydrag(); // set a function to be called on a drop event $("#box1").ondrop(function(e, element){ alert(element + " Dropped"); }); }); </script>
You can attach a function to be called when an element is being dragged and also another function to be called when the element is dropped passing them as a parameter to .ondrag and to .ondrop functions of the plugin. The plugin will pass an event object and the current element as the parameter to the attached functions.
By default EasyDrag is set to stop event bubbling so you can drag a div around without any problem but if you have elements inside a div, like a form for instance, you need to enable event bubbling to be able to interact with them.
To enable event bubbling simply pass “true” to the easydrag function as in the following example:
$("#box1").easydrag(true);
You can use the methods .dragOff() and .dragOn() to disable and enable the dragging behavior respectively.
101 Responses
fromvega
July 14th, 2007 at 6:16 pm
1If you have any doubt, any suggestion or if you have found a bug and want to suggest a correction please feel free to leave a comment!
Karl Swedberg
July 14th, 2007 at 10:33 pm
2Very slick! now I’m off to think up some fun uses for this. Thanks for the cool plugin.
Also, you ought to post it on jquery.com/plugins/. I’m sure others will appreciate it as well.
Datrio
July 16th, 2007 at 5:41 am
3Bug in Firefox 2.0 under XP. When I start dragging, the text outside of the box is selected. Not sure what’s the jQuery way of stopping the default event, if there’s no specific thing, there’s always:
e.cancelBubble = true;
if (e.stopPropagation) e.stopPropagation();
Jeff
July 16th, 2007 at 12:18 pm
4It looks like you should set the z-index of the object. It’s sitting under text if I move it over text and then I can no longer grab it. Also on firefox 2.0 on xp
fromvega
July 16th, 2007 at 2:07 pm
5Hello Datrio, thank you for the information! The fixed version is already available for download. It turns out that jQuery already have this implemented, the event handler just need to return false to stop event bubbling.
fromvega
July 16th, 2007 at 2:17 pm
6Hello Jeff, good point. I have set the code to set the z-index property to 10000. It may help for quickly deployment but you should set the z-index by yourself if you need precise control over the elements layering.
Stephan Beal
July 30th, 2007 at 12:24 pm
7Nice plugin. i would highly recommend getting rid of that SpiderMan logo at the top of the page, though. If someone from Marvel sees it you’re gonna get a letter from their lawyers.
fromvega
July 30th, 2007 at 1:13 pm
8And what about Chucky? hehe
Rob Honig
July 31st, 2007 at 7:46 am
9Chucky is OK..
Thnx.. was searching for this.
djot
July 31st, 2007 at 10:43 am
10-
great, lost my post because of a but in this shit comment window.
again in short: could you please provide an example of draggables and accepting droppables?
djot
-
fromvega
July 31st, 2007 at 1:40 pm
11I’m sorry djot, I was testing an anti-spam plugin. It indeed stops spams but I disabled it since other people may encounter problems like you did (maybe your web development toolbar had javascript disabled?).
So, now answering your question: you can achieve the “droppables” behavior using the .ondrop function with a sort of collision detection code. I did not include “droppables” in the source code because I wanted a clean and short plugin. But I may include it on demand.
To give you an idea of what I’m talking about I have coded a simple example that you can find at:
http://fromvega.com/code/easydrag/drop.html
Bye!
Colin
August 4th, 2007 at 7:52 pm
12Hi there,
Just found this and I’m trying to use it. Unfortunately, using the copy of the plugin above and jQuery 1.1.1, I get an error:
$(”#admineditmenu”).easydrag is not a function
Obviously, I’m trying to add draggin to a div called admineditmenu, and I am doing so with this command:
$(’#admineditmenu’).easydrag();
Am I missing something?
fromvega
August 5th, 2007 at 12:18 am
13Hello Colin,
I’m sorry but I have not tested it with jQuery 1.1.1. But it seems not to be a jQuery problem (maybe I’m wrong) but are you sure that you are including all the .js files correctly? Could you try using the most recent version of jQuery just to be sure if the error persists?
By the way, the correct form to call is “.easydrag()”
See you!
semelak1
August 5th, 2007 at 8:01 am
14Hello ,
When setting the width/height of the box to auto or to a percentage (60% for example), the shape pf the dragged div changes while dragging !! any resolution/work around for this ??
Thanks
fromvega
August 5th, 2007 at 12:55 pm
15Hello semelak1,
The problem seems to be that you are not setting your div as absolute positioned and haven’t set the parent position to “relative”. When you call easydrag(), the plugin will set the element positioning to absolute so you can drag it around. Therefore, some previous relations that the element had with others will be invalidated and others will change to reflect the new relations.
So let’s say that you want to drag the element #freebox and that it is inside another box called #staticbox. #staticbox have no position property defined and have width set to 500px, #freebox have no position property defined as well and have width set to 50%. So #freebox will be 250px wide.
Then when you apply the plugin, #freebox will no longer use the #staticbox to calculate the 50% width but the next relative positioned element (at least it’s what we expect). If there is no relative positioned element as its ancestor the #freebox width will be calculated based on the document width. So that’s probably why the size of your div is changing.
You can solve this by setting absolute values for the width and height or setting the “position” property of its parent to “relative”. This means adding “position: relative” to #staticbox in the example given.
I hope it helps!
Miguel Angel Mayol
August 7th, 2007 at 3:43 am
16Hi there, I’m using your plugin with a div which is contained into another div. The thing is that sometimes I get to drag the container div instead of the inner div although I haven’t assigned the drag’n'drop functionallity to the container div.
Can you tell me why this happens?
Good job though.
fromvega
August 7th, 2007 at 12:08 pm
17Hello Miguel,
I tried to reproduce the behavior you described here without success.
Everything worked as expected. Are you sure you are not assigning the drag’n'drop functionality to the wrong element? Maybe the ID of the element is being duplicated or something like that?
It will be easier to help if you make your code available somewhere.
Thank you!
Stanoo Chang
August 20th, 2007 at 4:50 am
18I downloaded the script and gave it a try. However, the first drag position was not good with IE … so, here’s a quick fix to use offsetTop instead of css(”top”) and offsetHeight.
line 125-126
- lastElemTop = parseInt($(this).css(”top”));
- lastElemLeft = parseInt($(this).css(”left”));
line 130
- if(isNaN(lastElemTop )) lastElemTop = lastMouseY - this.offsetHeight/2;
- if(isNaN(lastElemLeft)) lastElemLeft = lastMouseX - this.offsetWidth/2;
+ lastElemTop = this.offsetTop;
+ lastElemLeft = this.offsetLeft;
erica
August 24th, 2007 at 5:28 am
19Hi there, I’m using your plugin with a div which is contained into another div. I would like to limit the div drag inside a certain range (div id=”150″).
how can I do?
thanks
fromvega
August 25th, 2007 at 5:46 pm
20Thank you Stanoo Chang, it works much better now!
fromvega
August 25th, 2007 at 6:22 pm
21Hello Erica,
Since the main objective of this plug-in is to provide the core functionality of a drag-and-drop element it doesn’t have such a feature but you can achieve that using the .ondrag function.
Put inside it a code to get the coordinates of the boundaries of the element and check if it’s inside the limits you want it to be. If it is outside set the respective coordinate to equal as the limit.
I have coded a simple example for you. It works fine in Firefox but maybe it needs some fix to work properly in IE. I hope it gives you a direction to go:
http://fromvega.com/code/easydrag/prison.html
Bye!
Erica
August 27th, 2007 at 5:23 am
22thank you very much
Alex
August 28th, 2007 at 5:36 am
23thx for the plugin! it works fine, with a small exception.
when you click the div you want to drag (ie the yellow box on the first line of text) it attaches to the mouse on the second line of text. (it jumps a little downwards) how do u solve this?
have a nice day!
squitta
August 28th, 2007 at 12:33 pm
24Hi fromvega,
I switched over from wzdragdrop to jquery and easydrag, because easydrag is giving me a much higher performance on dragables containing videos :))
But as a matter of fact forms in dragables are not really working anymore. Could you please give me a hint how I can make my input fields work in jquery.
Thank you and best regards!
Squitta
squitta
August 28th, 2007 at 12:58 pm
25Yeah, I figured out a work around. On Click I am just given the element the input field the focus. If you find out something better, let me hear.
Thank you very much for your wonderfull script. I guess you heared it pretty much.
Best Regards,
Squitta
squitta
August 28th, 2007 at 1:01 pm
26Mh, as I can see, now the cursor is not placed where I click. Instead its placed at the end of the tunnel hehehehe
So still a workaround is needed :))
squitta
August 28th, 2007 at 1:03 pm
27Hey for your spiderman problem, try to find a spiderman, which is older than 30 years. I had a superman comic from 1969 as I can remember.
Just check out, you will find an pretty old one :))
fromvega
August 28th, 2007 at 5:46 pm
28Hello squitta, I’m a little busy these days but I’ll take a look at it later and try to find a way to make it work!
Thank you for the audience!
fromvega
August 28th, 2007 at 11:42 pm
29Hi squitta,
try downloading the script again (I have uploaded a new version) and now use $(”#yourdiv”).easydrag(true); and then check you form. It should work!
By passing “true” you tell EasyDrag to enable event bubbling and then you can get focus on the form elements.
Bye!
LeoW
September 8th, 2007 at 9:39 am
30Hi,
Here is a patch to avoid the element movement glitch when dragging a non-absolute positionned element.
it comes in replacement of the $(this).css(”position”, “absolute”) line in the mousedown handler.
// dynamically obtain element position on the page
var mytop=0, myleft=0;
var obj= this;
while( obj) {
mytop+= obj.offsetTop;
myleft+= obj.offsetLeft;
obj= obj.offsetParent;
}
// set it as absolute positioned
$(this).css( { position: “absolute”, top: mytop+”px”, left: myleft+”px” });
Possible improvement: calculate only when top and left attributes of the element are not available.
satts
October 7th, 2007 at 12:04 am
31Thanks a bunch… Was looking for this plugin. jQuery rocks
Philippe
October 11th, 2007 at 6:53 am
32Works ok - only did a small modification so the callbacks transmit the dragged element:
// mousemove
dragCallbacks[currentElement.id](e, currentElement);
// mouseup:
dropCallbacks[currentElement.id](e, currentElement);
Troy
October 18th, 2007 at 9:54 pm
33For those who wish to title=”/packer/”>pack easydrag.js, semicolons are required at the end of the function definitions (lines 44,55,87,94 & 133).
Thanks for the plugin, fromvega!
aiya
October 20th, 2007 at 12:18 am
34how to make like this “http://blog.xilinus.com/prototype-portal/test/index.html”
Philippe
October 22nd, 2007 at 10:57 am
35Looks like there is a bug about the easydrag ID:
// if no id is defined assign a unique one
if(undefined == this.id) this.id = ‘easydrag’+time();
I fixed it this way:
// if no id is defined assign a unique one
if(undefined == this.id || !this.id.length) this.id = ‘easydrag’+(new Date().getTime());
fromvega
October 22nd, 2007 at 12:37 pm
36Hello guys! Thank you for the efforts in making this plug-in better. I was voyaging but now I think I’ll be able to update it more often. I will make a new version of the plug-in with all the improvements soon! Thank you!
Jeff
October 23rd, 2007 at 7:42 pm
37Interesting script. How difficult would it be to go one step further and onDrop check to see if it is inside of a specified area or div? kind of like moving a file to a recycle bin. I can see some interesting applications for this.
Silence
October 27th, 2007 at 4:45 pm
38Well i did everything you said with it and it still doesen’t work … It retrurns a script error like this\
$(”#box1″).easydrag is not a function
(no name)()index.html (line 21)
ready(function())jquery-1.2.1.js (line 1932)
init(function(), undefined)jquery-1.2.1.js (line 70)
jQuery(function(), undefined)jquery-1.2.1.js (line 20)
jQuery(function(), undefined)jquery-1.2.1.js (line 21)
(no name)()index.html (line 19)
to the wait list jQuery.readyList.push()jquery-1.2.1.js (line 1937)
(no name)()jquery-1.2.1.js (line 1961)
each([function()], function(), undefined)jquery-1.2.1.js (line 585)
ready()
I’m new in using jquerry andeven newer in programing:). So if you could help … i will be very very glad
Gracias
engine80
October 31st, 2007 at 6:15 am
39Looks like a great script.
Im hoping to use it to allow a drag and drop ‘connection’ maker. I will have a series of options, and dropping one to another will create a connection.
I guess all i need to know is is it possible to know from
ondrop()… where its been dropped to… so i could say programatically, id ‘thing1′ has been dropped on id ‘thang2′… ultimately, they would all be draggable objects, in a way.
perhaps im being too vague
fromvega
October 31st, 2007 at 10:59 am
40There is no such functionality yet. Next release will incorporate all user contributions. You will be able to detect which element was dropped but for now you will need to implement your “target” code. There is an example linked in the comments, give it a look. Thanks!
Colin Brumelle
October 31st, 2007 at 1:39 pm
41Hey! Thanks for a killer plugin!
I’m trying to stick a form in a div, and then make that div draggable, but when I do so, the form becomes not usable. Specifically, I am unable to enter content into a text field in FF, although (strangely) the submit button works. I thought this was a z-index thing, but I’ve been playing with it for a while now and no luck.
Any hints?
Colin Brumelle
October 31st, 2007 at 2:46 pm
42Sorry - just some more clarification - I’m using $(”#content”).easydrag(true); to enable event bubbling, but when I try to select text in the box, the whole div moves, rather then selecting the text. Can I use ‘bind’/'unbind’ to temporarily disable/enable the drag behavior when a form field is selected? Not sure how to do this though…
marcin kolonko
November 4th, 2007 at 12:12 pm
43hi,
thanks for the plugin, makes life easier…
when i drop a div, that has an click event, the event is triggered. how can i prevent this?
i tried to unbind the click event when i start dragging, and bind it again on mouseout, but then the event is triggered always one time more then before…
thanks!
fromvega
November 5th, 2007 at 5:39 pm
44Hi Colin Brumelle,
I have added two methods to the plugin: .dragOn() and .dragOff() that you can use to pause and restart dragging. I have made a test with forms with the following code. It works but not perfectly. Give it a try and return to us if you find a better solution.
$(”#form_div input”).click(function(){
$(”#form_div”).dragOff();
});
$(”#form_div input”).blur(function(){
$(”#form_div”).dragOn();
});
fromvega
November 5th, 2007 at 5:41 pm
45Hello marcin,
I have checked your site but I couldn’t see the click event after dropping!
David K Roberts
November 6th, 2007 at 7:21 pm
46What I would really like to see is a way you can specifify an Inner Div as the drag state…. this way you can move the whole object, but you can only drag the title. (I am using this as a way to create virtual windows on an application… It works great until I have a user try to use a combobox… it then still drags when I look at an elongated select box
fromvega
November 6th, 2007 at 7:40 pm
47Yeah… I’m planning to add a few more functionalities to the plugin as soon as I have more free time. But the original objective of this plugin was to provide a simple drag-and-drop functionality so others could use it as a base. But since pretty much everyone is seeking for drop targets, drag handlers and so on I may code them…
alain
November 25th, 2007 at 3:20 am
48Be nice to add a resize functionality too.
Patrick
November 26th, 2007 at 11:14 am
49is there a way to do a form submit when doing the .ondrop?
I’d like to use this to submit hidden fields to a form on another page on my site and then update a div on the current page showing success depending on server response. I don;t want the user to leave the current page but do the form submit in the background.
Regards,
Patrick
fromvega
November 27th, 2007 at 3:10 pm
50Hey Patrick, you can do it with AJAX. Just call the proper function that will make a remote post from inside .ondrop
Carlos
December 3rd, 2007 at 5:04 pm
51How to make a title div dragging the box only when the mouse is over the title?
fromvega
December 6th, 2007 at 4:31 pm
52Carlos, you will need to implement this… This script just provides the basic functionality of drag and drop.
Sascha Braun
December 7th, 2007 at 4:52 pm
53Hi fromvega,
I am using lots of dragable layers in my applications, all are based on easydrag, I dropped out, wzdragdrop, because of performance issues. Most of the time easydrag and the wanted functionality is working fine in mozilla.
I am using easydrag layers as fixed objects on the screen, and store the position of the layer thru ajax on the webserver, so if a user clicks on another page the layer reapears at exactly the same spot, where the user left it.
But in internet explorer the dragable layer always is just thrown below the content, but as soon as the user clicks on the layer, the layer is moved to the spot, where it normaly is expected.
Please take a look at the website I posted here (http://www.ajdila.com/de/), sorry that the english translation is not finished yet. If you click on one of the products and put the product into the shopping cart, the dragable layer appears. Please play with it, maybe you are better able to find out why its not working as expected.
Thank you very much.
Sascha
fromvega
December 7th, 2007 at 5:59 pm
54Hello Sascha,
I’m a little busy right now to take a more concise look at your source code. But I have tested here with IE7 and the layer didn’t move at all :S
I think it’s something related to CSS. Did you set the “position” property of the layer to “absolute”?
Since it should be absolute positioned, try putting your layer outside any other tag, this may prevent future problems.
Try to validate your code withe the W3C validation tool, maybe something isn’t right.
Thank you,
fromvega
Prasad
December 21st, 2007 at 12:30 pm
55Hi Engine80
To your problem you can use the below solution
drop: function(ev, ui) {
var dropguy = $(ui.draggable.element).clone();
var id = dropguy.attr(”id”);
var divdata = document.getElementById(id);
var hdSave = document.getElementById(’hdSave’);
var hdType = document.getElementById(’hdType’);
hdSave.value = dropguy.attr(”id”);
hdType.value = this.id; // this is nothing but your droppable control.
$(”.drop”).each(function(i, node){$
(node).droppableDestroy();});//Fix IE bug
var prm = Sys.WebForms.PageRequestManager.getInstance();
prm._doPostBack(’UpdatePanel1′, ”);
//document.form1.submit();
//$(this).append(divdata.outerHTML);
}
Sascha Braun
December 27th, 2007 at 2:56 pm
56Please check out this url:
http://ajdila/de/galleries/sascha/product-commercials/
It is now working with the moving layers and the storage in the servers or theire position. But the layers cant get shown as they should appear above a flash movie.
Maybe somebody has an Idea?
Thank you.
fromvega
December 27th, 2007 at 8:55 pm
57Hey Sascha, I can’t really say for sure what’s happening since I never messed up with floating divs and flash. But try setting the z-index property of the flash movie to a smaller value (or vice versa) and see what happens!
Sascha Braun
December 29th, 2007 at 5:32 am
58I solved the problem, i still dont know how it works in internet explorer, because I dont have one.
You just have to use your plugin to create dragable layer, with lets say posiiton absolute, which supports the internet explorer then. Within the dragable layer you have to create another layer at a fixed size. The nested layer has to have a position:fixed attribute, which says that within the dragable the nested layer is fixed. From that moment the nested layer comes along with a z-index set to infinite. Flash behind a dragable is no problem anymore.
:))
Lawrence
January 13th, 2008 at 8:17 am
59Hey,
Im trying to use your code to be able to drag a photo around inside a div and keep the overflow:hidden property so only certain parts of the photo are shown..
It seems that the photo is removed from the div is resides in even tho i have set the z-index of the photo to -99999 (as well as in your drag.js code)
any iedas?
fromvega
January 13th, 2008 at 7:09 pm
60Hello Lawrence,
I think the z-index property has nothing to do with what you want. Your problem is probably due to the the div positioning, it’s position property is set to absolute. You may try changing it to position: relative.
Let me know if it works!
Bye.
Glenn
January 21st, 2008 at 1:06 am
61Hi Fromvega,
Thanks a lot for this contribution, I just use easydrag to make the user able to drag a small google map div like a window. Works very well. Didn’t have a need to drag/drop just to drag.
Behavior is also very ok, google map inside div still drags fine without window. thanks a lot!!
I actually applied it on the cluetip plugin (drag a show help) as it was giving me some issues in correct placement, I enable dragzoom after the cluetip is show and that also works fine. so it works well enough with the rest. I kinda start owing my life to jquery… since I discovered this …. I can’t get no sleep
Glenn
Jabi
January 26th, 2008 at 12:57 pm
62Hi Fromvega!
First of all, nice piece of code you have! good job!
I would like to contribute with a little workaround in your pluggin for ussing it with the also Jquery impromtu pluggin (http://plugins.jquery.com/project/Impromptu).
The main problem is the div impromptu creates has some left margin assinged on its creation, so you pluggin always move the div those marginLeft pixels to the left.
I have fixed it dettecting and substracting (if applies) those pixels to the “spanX” var which determines the left positon of the dragable object in your pluggin:
(Line 55:)
var spanX = (pos.x - lastMouseX) + Math.abs(parseFloat($(currentElement).css(”marginLeft”)));
I haven’t test it in any browser but FF2, and maybe it will be different with a non negative marging…
Anyway, i thought it could be intersting checking for margins in that “updatePosition” function.
Jabi
Jabi
January 26th, 2008 at 12:58 pm
63Actually the line working with both positive and negative margins would be like this:
(Line 55:)
var spanX = (pos.x - lastMouseX) - parseFloat($(currentElement).css(”marginLeft”));
jonah
January 29th, 2008 at 6:33 am
64Hi
I’ve made a couple of improvements to your script. I’ve added an onDragStart callback and fixed a couple of bugs. Im using the modified version over at 64squares. If you are interested I can give them to you.
Jonha
fromvega
January 29th, 2008 at 11:08 am
65Hi Jonah,
Yeah, it would be great to have a look at your code. Maybe you could send it to us explaining your additions and the bugs.
Thank you
Iain Munro
February 21st, 2008 at 12:37 am
66Evening
I am using Sharepoint and trying to get various things working within a CEWP - sometimes that work and sometimes they don’t.
I came across a good accordion piece of jquery code that I got working, then I thought it would be nice drag the accordion around the screen.
I now have it dragging, but the accordion piece has stopped working.
Any ideas ?
Iain
fromvega
February 22nd, 2008 at 4:22 pm
67Hello Iain,
I didn’t read you code, but try calling the easydrag method passing “true” to it. Like the following example. This will enable event bubbling and you will be able to interact with the elements inside the drag box.
$(”#box1″).easydrag(true);
Bye
eGandalf
February 28th, 2008 at 4:06 pm
68Beautiful. JQuery rocks and this is a fantastic plugin. EasyDrag indeed!
ctraos
March 4th, 2008 at 2:47 pm
69muchas gracias, muy buen trabajo !!
Bill Lee
March 4th, 2008 at 6:47 pm
70Im thinking about using this for an administration panel where the admin could move the most import doms to wherever they want. Is there way for the script to remember its location for the next time that user comes back to the page ?
fromvega
March 6th, 2008 at 10:57 pm
71Hello, Bill Lee! To achieve that you may save the position directly into cookies or, what I prefer, you may use a server-side script to save the state and then dynamic generate your Javascript. I may write an example for this later.
Craig
March 14th, 2008 at 2:16 am
72I looked over your code and found a better way to fix the no id issue. Use the elements instead of their ids.
To do this:
-remove the line with the new Date() hack
-remove every instance of “.id”
-replace every “on” and “off” with true and false respectively
-remove “!= undefined” on line 66
This method is smaller, cleaner and is not affected if an id attribute changes.
fedmich
March 16th, 2008 at 6:38 am
73Great script, thanks for this, how about locking the movements or setting “Dragabble area”
I’m supposed to make a drag and drop callout/bubbles and then adding of text on it.
Any ideas on this. THanks in advance
fromvega
March 17th, 2008 at 12:31 pm
74Hello Graig, thanks for the insight! I’m going to address this when I find a little time to mess again with EasyDrag. Bye!
fromvega
March 17th, 2008 at 12:35 pm
75Hello fedmich, to lock movements you can use .dragOff() so you won’t be able to drag the element until you call .dragOn(). But there are a lot of requested features that I plan to implement as I have more spare time, like limit area, drop area, handles etc. See you!
fedmich
March 17th, 2008 at 12:50 pm
76limit area would be nice, I need it more than the other features now. Anyway, good luck on your programming and your blog
fromvega
March 17th, 2008 at 2:17 pm
77Fedmich, EasyDrag was created to be used as a base for future implementations. So if you want to write your own code for the “limit area”, it shouldn’t be that difficult. You could use .onDrag method to get the boundaries of the draggable object and compare it with the boundaries of the “limit area”.
If you check the previous comments you will see that I have discussed this before and that I also developed a quick and crude example of this.
Here are the links to save you time:
http://fromvega.com/code/easydrag/drop.html
http://fromvega.com/code/easydrag/prison.html
They need polish to allow a more generic usage. But I hope they can give you a good insight!
Neal
March 18th, 2008 at 2:47 pm
78Thank you, thank you for this plug-in.
I used it to poke fun at Hillary Clinton:
http://gielladesign.com/fun/hillary/hillary.html
You made it so easy to create the effect I wanted. It took me seconds to write the code.
xddxz
March 26th, 2008 at 6:52 am
79Nice plugin.
Thanks a lot!
Arun
April 3rd, 2008 at 3:01 am
80Hi,
This one is a very good plugin.Even after hiding the layer the “plus” symbol exists in Internet Explorer but in Mozilla it is working fine.I want to remove the “plus” symbol.Please help me.
fromvega
April 3rd, 2008 at 2:13 pm
81Hello Arun, what do you mean by the “plus” symbol? I suppose you mean the arrows that appear over the divs that can be dragged, correct me if I’m wrong.
So how are you hiding the div? You should try “display: none;” if you are using “visibility: hidden”. If it doesn’t work you can always change the cursor type of the element, like this: “cursor: default”.
Bye!
Dilip
April 12th, 2008 at 4:06 am
82Any solution for this scenario…
I have a parent div which consist of two parts. One head and body part. After clicking and dragging the head part, the whole parent div (head + body part) should move.
Pls gime a soln….
fromvega
April 14th, 2008 at 5:34 pm
83Hello Dilip,
As I said before, this plugin doesn’t provide all features as its main goal is to provide a base functionality for drag and drop.
But basically, to obtain the effect that you need, you should update the body element position in accordance with the head position every time it changes. Using ondrag() you can track the position of the header element.
I’m looking forward to code all requested features in the near future!
Keep an eye for the updates!
Oleg
April 18th, 2008 at 10:06 am
84Hi fromvega,
Thanks for your great plugin! I’m a novice in JavaScript and tried to use native jQuery UI instruments for dragging, but they are too heavy and leaks some features, as for me.
I’m using your plugin to develop an online city map ( http://etabua.net/tmap ). It’s on an early stage of development, but when i’m clicking the map with any instrument, it has been moved 1px left and 1px top all the time. I have to reset it to it’s default position all the time. I activate dragOn() only when the Hand tool is being selected. All other instruments have dragOff() call instead.
Thanks for help.
Tony
April 21st, 2008 at 6:30 pm
85Hi, this is a great plugin. The only little issue I see is in the Safari browser, the cursor with crosshairs doesn’t change to the pointer(hand) icon when mousing over links in a draggable popup window. Probably more of a safari issue than a bug, as this works flawlessly with IE6, 7 and FF 2.
Stevan Little
May 3rd, 2008 at 12:01 pm
86Excellent plugin, I only needed on added feature, the ability to manually force the same effects as the onmouseout action. The code was simple, here it is, feel free to add it into the plugin if you like:
// force the same action as onmouseup
$.fn.stopDrag = function () {
isMouseDown = false;
if(dropCallbacks[currentElement.id] != undefined){
dropCallbacks[currentElement.id](e, currentElement);
}
return false;
};
I needed this mostly because I have a scolling DIV (overflow:auto) inside the draggable container.
- Stevan
Aaron
May 12th, 2008 at 12:20 pm
87Nice plugin, but is there a way to restrict the draggable div inside another container div?
Aaron
May 12th, 2008 at 12:25 pm
88Ahh.. I just saw comment #20 with the answer I need.. Thanks alot
Batisteb
May 19th, 2008 at 8:43 am
89Hi,
Thx for your plug in. I have used it as a fundation for a Drag & Drop and Resize plugin : http://batiste.dosimple.ch/blog/2008-05-18-1/
OSS FTW
Olgg
May 20th, 2008 at 4:15 am
90Thanks for this wonderful code, the Jquery draggable event don’t seems to work with me.
Realy nice work.
hunka
May 26th, 2008 at 6:21 am
91Its really nice to know how Jquery helps….thanks mate….
Uzbek
May 30th, 2008 at 8:44 am
92Great plugin. Was looking something like it.
Del.icio.us && digging right away…
Thanks yet again.
Pablo A
June 23rd, 2008 at 6:47 pm
93I will create a customizable story book. In the middle of the page I will have a DIV that will represent the book page. On the right side I will have some 3/4 characters, 10 accessories and so on.
I want to drag’n'drop the elements into the book page and then get the coordinates of each object dropped into the div since I want to save these coordinates for later print the book. I also want if the user drag’n'drop the character outside the page div move it to the original place.
Do you know of something similar to what I am looking for? Maybe a similar situation or solution?
Thanks in advance to all the community!
Lapubell
June 25th, 2008 at 5:33 pm
94I’m developing a fun little site that works like a Mac/Linux OS for my band’s website. I love this plugin that you have but I am trying to make it work like a handle. Any input as to how to make a child div the dragable object that drags the parent div?
fromvega
June 26th, 2008 at 6:25 pm
95Hi Pablo A and Lapubell, I got some time and I will try to code this requested features today. Keep an eye for updates!
Lapubell
June 26th, 2008 at 6:33 pm
96that would be way too awesome! got a paypal donate button? I love supporting OSS projects…
you jquery coders are awesome. i’m still wrapping my brain around good ol javascript.
fromvega
June 28th, 2008 at 12:41 am
97Hi Lapubell, just wanted to let you know the code for the handler is done but I’m having a little problem with the ftp, so that’s why I didn’t upload the code yet! Hope to have it solved soon.
fromvega
June 28th, 2008 at 12:52 am
98Lapubell, please download the new code from this temporary url: http://fromvega.com/wordpress/wp-content/uploads/2008/06/jqueryeasydrag-handler-test.js
So here goes a little explanation: for the handle to work it must be a child of the element you want to drag around. Then you call .setHandler(’handler_id’) to make it work.
$(”#box2″).easydrag(true);
$(”#box2″).setHandler(’handler3′);
You should pass ‘true’ to the easydrag() method to enable event bubbling. Maybe it should be automatically set when calling setHandler(). I’m going to wait for some feedback before posting the new version.
Bye!
cn
June 29th, 2008 at 9:11 am
99Awesome!Thx for the nice script.
regards from China.
Lapubell
July 2nd, 2008 at 5:07 pm
100this is working fantastically.
the OSX/Linux layout is coming along greatly! to see the progress of the page go to http://www.aneveningwithdotmatrix.com/os.php.
the only windows that work currently are the home, about and music, but it’s coming along nicely!
thanks to your awesome revision!
PS, there is a catch to see if you are using internet explorer, so if you are using that, you won’t be able to pass. I recommend FireFox 3.
fromvega
July 2nd, 2008 at 5:47 pm
101Lapubell, I’m glad to see it has been useful for you! Your project looks cool! Just a tip, differently from my previous comment, you shouldn’t need to pass “true” to the easydrag() method anymore if you are calling setHandler() after. Give it a try!
RSS feed for comments on this post · TrackBack URI
Leave a reply