22

次のように、他の円に囲まれた円を (アニメーションなしで) 作成したいと思います。

私の考え

しかし、phonegapアプリを組み込みたいので、ファイルサイズを大きくしたくありません。

誰かがプラグイン/メソッドまたはその他のソリューションを知っていますか?

インターネットで検索しましたが、ファイルのサイズが大きくなりすぎる方法が見つかりました。

4

6 に答える 6

38

この質問のJavaScriptの側面に誰も対処しませんでした。以下は、html、css3、および javascript を使用して、親円の中心の周りに 6 つの完全な間隔の円を描画する完全な (手早く汚い) Web ページです。純粋な JavaScript を使用するため、jquery ライブラリを参照する必要はありません。コードからメソッドを簡単に抽出して、サテライト サークルの数、親の中心からの距離、親とサテライトの半径、サテライト オフセットなどを制御する方法を確認できるはずです。

var div = 360 / 6;
var radius = 150;
var parentdiv = document.getElementById('parentdiv');
var offsetToParentCenter = parseInt(parentdiv.offsetWidth / 2); //assumes parent is square
var offsetToChildCenter = 20;
var totalOffset = offsetToParentCenter - offsetToChildCenter;
for (var i = 1; i <= 6; ++i) {
  var childdiv = document.createElement('div');
  childdiv.className = 'div2';
  childdiv.style.position = 'absolute';
  var y = Math.sin((div * i) * (Math.PI / 180)) * radius;
  var x = Math.cos((div * i) * (Math.PI / 180)) * radius;
  childdiv.style.top = (y + totalOffset).toString() + "px";
  childdiv.style.left = (x + totalOffset).toString() + "px";
  parentdiv.appendChild(childdiv);
}
#parentdiv {
  position: relative;
  width: 150px;
  height: 150px;
  background-color: #ac5;
  border-radius: 150px;
  margin: 150px;
}

.div2 {
  position: absolute;
  width: 40px;
  height: 40px;
  background-color: #ac5;
  border-radius: 100px;
}
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
  <title></title>
</head>

<body>
  <div id="parentdiv"></div>
</body>

</html>

于 2013-06-22T14:19:19.727 に答える
15

円を作成するには、 を使用しますborder-radius: 50%。次に、大きな円の周りに6 円divsを配置します。position: absolute

このようなもの: http://jsfiddle.net/yxVkk/

<div id="big-circle" class="circle big">
    <div class="circle one"></div>
    <div class="circle two"></div>
    <div class="circle three"></div>
    <div class="circle four"></div>
    <div class="circle five"></div>
    <div class="circle six"></div>
</div>

<style>
.circle {
    border-radius: 50%;
    width: 50px;
    height: 50px;
    background-color: red;
    display: inline-block;
    position: absolute;
}

.circle.big {
    width: 150px;
    height: 150px;
    background-color: blue;
    margin: 100px;
}

.one {
    left: -25px;
    top: -25px;
}

.two {
    top: -60px;
    left: 50px;
}

.three {
    right: -25px;
    top: -25px;
}


.four {
    left: -25px;
    bottom: -25px;
}

.five {
    bottom: -60px;
    left: 50px;
}

.six {
    right: -25px;
    bottom: -25px;
}
</style>
于 2013-05-17T16:35:39.803 に答える
1

css を使用すると、そのようなことを試すことができます。ただし、HTML5 のサークル タグを使用すると、より良い結果が得られます。

http://jsbin.com/etuzis/1/

HTML

<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>JS Bin</title>
</head>
<body>
  <div class=div2 style='top:12px; left:45px;'></div>
  <div class=div2 style='top:4px; left:160px;'></div>
   <div class=div2 style='top:94px; left:210px;'></div>
  <div class=div1></div>

  </body>
</html>

CSS

.div1{
  margin:40px 10px 10px 50px;
  position:relative;
  width:150px;
  height:150px;
  background-color:#ac5;
  border-radius:100px;
}
.div2{
  position:absolute;
  width:40px;
  height:40px;
  background-color:#ac5;
  border-radius:100px;
}
于 2013-05-17T16:34:48.300 に答える
1

<div>等しい with と height を持つa に border-radius:50% を追加し、その上に background-color を配置すると、CSS から円が作成されます (軽い負荷)。

.big_circle {
  width:10em;
  height:10em;
  border-radius:50%;
  background-color:blue;
}

その後、position:absolute および負のマージン トリックを使用して、円を画面の中央に直接配置できます。

.big_circle {
  width:10em;
  height:10em;
  border-radius:50%;
  background-color:blue;

  position:absolute;
  top:50%;
  left:50%;
  margin-left:-5em;
  margin-top:-5em;
}

小さい円のスタイルを処理するクラスを作成します。

.little_circle {
  width:3em;
  height:3em;
  border-radius:50%;
  background-color:green;
  position:relative;
}

次に、ID (またはそれらを識別するその他の方法) を追加して、大きな円と比較して相対的に配置します。

#little_one {
  bottom:1em;
  right:2em;
}

#little_two {
  bottom:6.5em;
  left:3.5em;
}

#little_three {
  bottom:7em;
  left:9em;
}

// etc...

サンプル付きの CodePen を次に示します。

于 2013-05-17T16:45:23.010 に答える
0

誰かがコメントで言ったように、設定border-radius:50%してから絶対に配置する必要があります。リンクを説明するためにダミーのjsfiddleを作成しました:

        circle{
    width : 50px;
    height : 50px;
    border-radius : 50%;
    background: red;
    position : absolute;
    top : 50px;
    left : 150px;
}
.small_circle_1{
    width : 20px;
    height : 20px;
    border-radius : 50%;
    background: blue;
    position : absolute;
    top : -25px;
    left : 15px;
}
.small_circle_2{
    width : 20px;
    height : 20px;
    border-radius : 50%;
    background: blue;
    position : absolute;
    top : 15px;
    left : -25px;
}
.small_circle_3{
    width : 20px;
    height : 20px;
    border-radius : 50%;
    background: blue;
    position : absolute;
    top : 55px;
    left : 15px;
}
.small_circle_4{
    width : 20px;
    height : 20px;
    border-radius : 50%;
    background: blue;
    position : absolute;
    top : 15px;
    left : 55px;
}
于 2013-05-17T16:36:43.050 に答える