Solved

Lines between circles

Posted on 2014-10-04
4
108 Views
Last Modified: 2014-10-05
The circles in this code must be linked by a line, between the center circle and the others.
The other thing that I need is that the circles created need to be just like the first one, so that I can click on them and they also show a certain number of circles without it being an exact copy (they can have a different number of circles linked to them).
Well any help would be much appreciated.

Here is the code:

<!DOCTYPE html>
<html><head>
<meta http-equiv="content-type" content="text/html; charset=windows-1252">
<title>Rodrigo</title>
<style type="text/css">
#circle-container {
  position: relative;
  width: 500px;
  height: 500px;
  margin: 0 auto;
  border: 0px solid green;
}
.circle {
  position: absolute;
  width: 40px;
  height: 40px;
  border-radius: 40px;
  background: red;
  left: 230px;
  top: 230px;
}
.blue {
  background: blue;
}
.green {
  background: green;
}
.yellow {
  background: yellow;
}
.orange {
  background: orange;
}
.pink {
  background: pink;
}
.purple {
  background: purple;
}
</style>
</head>
<body>
<div id="circle-container">
  <div class="circle animate blue"></div>
  <div class="circle animate green"></div>
  <div class="circle animate yellow"></div>
  <div class="circle animate orange"></div>
  <div class="circle animate pink"></div>
  <div class="circle animate purple"></div>
  <div id="circle" class="circle"></div>
</div>
<script src="jquery.js"></script>
<script type="text/javascript">
var clicked = false;
var distanceToMove = 100;
$(function() {
  $('#circle').click(function() {
    if (clicked) return;
    clicked = true;
    var total_circles = $('#circle-container .circle.animate').length;
    var angle = (Math.PI * 2 / total_circles)
    $('#circle-container .circle.animate').each(function(indx, item) {
      var top = distanceToMove * Math.cos(angle*(indx-1));
      var left = distanceToMove * Math.sin(angle *(indx-1)); 

      $(this).animate({left: "+=" + left, top: "+=" + top}, 1000);
    });
  });
});
</script>



</body></html>

Open in new window

0
Comment
Question by:Rodric MacOliver
  • 2
  • 2
4 Comments
 
LVL 38

Expert Comment

by:Tom Beck
ID: 40361799
Try this version.

http://jsfiddle.net/yq8umq15/
0
 

Author Comment

by:Rodric MacOliver
ID: 40361857
Tom Beck, than is just great, but when i click again on the circle it must retract...
Thanks a lot...
0
 
LVL 38

Accepted Solution

by:
Tom Beck earned 500 total points
ID: 40362865
0
 

Author Closing Comment

by:Rodric MacOliver
ID: 40362928
Lovely Tom, I still need something to be done but since I think its kind of different I'll be opening another question for it. Thanks a lot.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
HTML auto refresh to another site 4 28
How to get text of href without any ID using Javascript 9 23
Put POST values into cookies. 14 29
Ajax on ASP 2 32
OverviewThis article demonstrates a simple search form using AJAX. The purpose of the article is to demonstrate how to use the same code to render a page and javascript (JQuery) and AJAX to make subsequent calls to refine the results. The princip…
There are a couple ways to attach a JavaScript function to dynamically created elements. You can make a new script for each element as it’s created or you can use delegation. Delegation allows a single script that is added at page creation to mat…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question