Home › Forums › JavaScript › Drag and Drop then Draw Line in JQUERY
- This topic is empty.
-
AuthorPosts
-
August 21, 2014 at 12:38 am #180078
Nestle
ParticipantHello,
I want to drag elements from datalist and drop them in a div.
when you drag an element you must draw a line from it to some point.
using asp.net and jqueryAugust 21, 2014 at 12:41 am #180079nixnerd
ParticipantWhy MUST you use asp.net?
August 21, 2014 at 12:48 am #180080Nestle
Participantsorry HTML not asp.net
August 21, 2014 at 1:02 am #180082nixnerd
ParticipantHa ha ha. I get them confused all the time myself :)
jQuery makes it pretty easy to create drag and drop elements. Could you try creating a Codepen so we can help?
August 21, 2014 at 1:15 am #180083Nestle
Participantplz check this:
http://codepen.io/Nestle/pen/aznyk
i need that when i drop an element to draw a line from it , and when drop another
element to automatically connected to the drawn line.could you help me?
August 21, 2014 at 1:16 am #180085Nestle
ParticipantAugust 21, 2014 at 1:18 am #180086nixnerd
ParticipantWell, first of all, your elements aren’t draggable yet. Let’s forget about the line for now.
See here:
August 21, 2014 at 1:34 am #180088Nestle
Participantplease check now
http://codepen.io/Nestle/pen/aznykAugust 21, 2014 at 1:40 am #180089nixnerd
ParticipantI’m not able to drag the numbers. I assume that’s what’s supposed to be happening.
August 21, 2014 at 1:47 am #180091Nestle
Participanti have tried it on a stand alone application and it works fine.
may be the jquery library.anyway when drop an item how to draw a line from that element
and automatically connected to seconde dropped element and so on.
could you help please?August 21, 2014 at 1:58 am #180093nixnerd
ParticipantLook into something like this:
http://stackoverflow.com/questions/4903530/how-to-get-the-position-of-a-draggable-object
You need to get the position of each element with a function that’s called every time you move anything. But… that’s a shipload of state management. Also… I’m not really sure how you should go about drawing the lines.
Typically, you’d use canvas for something like this. But… it looks like you’re trying to do some straight up DOM action. I would recommend this:
In theory, you should be able to pass your coordinates to some function that handles the drawing of these svg lines.
Godspeed Nestle.
Hey, is there any way you could make this your Gravatar:
August 22, 2014 at 1:07 am #180216nixnerd
ParticipantSnap.svg also makes things draggable. It’s pretty damn easy.
August 22, 2014 at 8:42 am #180272Nestle
ParticipantThank you so much NIX.
but i need an example if possible to draw a line between draggable elements.
i see the library JsPlumb, but i didnt know how to start.August 25, 2014 at 9:27 am #180532nixnerd
ParticipantThe first thing you need to be able to do is drag something and
console.log()
the new position. As long as you’re able to somehow return the new position… you should be able to re-draw the line as it moves.Now, AFAIK… this is NOT a trivial task. It may or may not work with SVG… I haven’t tried. It could surely work with canvas. But… canvas does have some limitations as far as I’m concerned.
June 16, 2015 at 7:01 am #203829zinuhe
Participant -
AuthorPosts
- The forum ‘JavaScript’ is closed to new topics and replies.