最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

javascript - Create a line between 2 floating divs and adjust to movement - Stack Overflow

matteradmin9PV0评论

I've got two floating divs which can be re-positioned by the user using drag and drop. I want to draw a line between the two divs and have it adjust itself (size and positions) to the movements of the divs.

The goal is to get some sort of chartflow/diagram alike construction within the browser.

What would be the best method to do this?

I've got two floating divs which can be re-positioned by the user using drag and drop. I want to draw a line between the two divs and have it adjust itself (size and positions) to the movements of the divs.

The goal is to get some sort of chartflow/diagram alike construction within the browser.

What would be the best method to do this?

Share Improve this question asked Jul 1, 2012 at 18:55 user6user6 2,0532 gold badges25 silver badges29 bronze badges 1
  • Can you post some kind of example of what you're trying to achieve, and also, what have you tried to implement to solve this problem? – Brandon Buck Commented Jul 1, 2012 at 19:02
Add a ment  | 

4 Answers 4

Reset to default 3

If you're going to do anything more than very basic drawing/figures, then I would remend a drawing library such as RaphaelJS. It greatly simplifies things for you. See an example: http://jsfiddle/sveinatle/RVykE/1/

That example is not a perfect implementation, but it shows how much help you get from Raphael.

JS Plumb:

http://jsplumb/jquery/demo.html

SVG, Canvas, or VML

Jquery, Mootools, or YUI

Here's a version using just HTML, jQuery and some trigonometry!
Still needs a bit of tweaking but it's mostly there.

http://jsfiddle/gKj35/2/

I can think of three ways:

  1. you can use svg
  2. you can use html canvas
  3. you can use pure html( divs with height = 1 will be horizontal lines, and divs with width = 1 will be vertical lines). You can bine these lines to create a line segment.
Post a comment

comment list (0)

  1. No comments so far