太阳系轨道HTML中心

用户4191887

在我的太阳系模型中,当您单击“切换轨道”时,它会显示所有熟悉的行星地球的轨道,但是您会注意到该环并不位于行星中心,而仅位于行星中心,我将如何制造它会在中间吗?

function myFunction() {
  for (var i = 0; i < 500; i++) {
    var x = Math.random() * screen.width;
    var y = Math.random() * screen.height;
    var star = document.createElement('div');
    star.className = 'star';
    star.style.left = x + 'px';
    star.style.top = y + 'px';
    document.body.appendChild(star);
  }
}
html {
  background-color: #000;
  overflow-x: hidden;
  overflow-y: hidden;
}
.star {
  position: absolute;
  width: 1px;
  height: 1px;
  background: white;
  z-index: -1;
}
.sun {
  position: absolute;
  height: 100px;
  width: 100px;
  top: 50%;
  left: 50%;
  margin-left: -50px;
  margin-top: -50px;
  border-radius: 50%;
  /*box-shadow: rgb(204, 153, 0) 0px 0px 50px 0px;*/
}
#button-change {
  position: absolute;
  top: 2px;
  left: 2px;
}
.earth {
  position: absolute;
  height: 25px;
  width: 25px;
  border-radius: 50%;
  box-shadow: green 0 0 25px;
}
.earth-orbit {
  position: absolute;
  height: 200px;
  width: 200px;
  top: 50%;
  left: 50%;
  margin-left: -100px;
  margin-top: -100px;
  -webkit-animation: spin-right 15s linear infinite;
}
.earth-lines {
  border-width: 1px;
  border-style: solid;
  border-color: white;
  border-radius: 50%;
  position: absolute;
}
.moon {
  height: 10px;
  width: 10px;
}
.moon-orbit {
  top: 50%;
  left: 50%;
  height: 50px;
  width: 50px;
  margin-left: -12.5px;
  margin-bottom: -37px;
  border: 1px solid rgba(255, 0, 0, 0.1);
  border-radius: 50%;
  -webkit-animation: spin-right 4s linear infinite;
}
@-webkit-keyframes spin-right {
  100% {
    -webkit-transform: rotate(360deg);
  }
}
<!DOCTYPE html>
<html>

<head>
  <title>Vanishing Act</title>
  <link rel='stylesheet' type='text/css' href='stylesheet.css' />
  <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
  <script type='text/javascript' src='script.js'></script>
  <script>
    $(document).ready(function() {
      $("button").click(function() {
        $('.earth-orbit').toggleClass('earth-lines');
      });
    });
  </script>
</head>

<body onload="myFunction()">
  <img class="sun" src="5.png">
  </div>
  <div class="earth-orbit">
    <div class='moon-orbit'>
      <img class="moon" src="http://space-facts.com/wp-content/uploads/moon-transparent.png" />
    </div>

    <img class="earth" src="http://www.polyvore.com/cgi/img-thing?.out=jpg&size=l&tid=74422923" />
  </div>
  <button id="button-change">Toggle Orbits</button>
</body>

</html>

亚历克斯·卡辛

.earth-lines静态放置.earth-orbit,因此调整.earth和的边距.moon是一个合理的解决方案。

另一方面,让我们思考一下。如果我们将其.earth-lines作为单独的div怎么办?像这样:

<div class="earth-lines">
</div>

<div class="earth-orbit ">
    <div class='moon-orbit'>
      <img class="moon" src="http://space-facts.com/wp-content/uploads/moon-transparent.png" />
    </div>
</div>

并且CSS.earth-lines如下所示:

.earth-lines {
    display: none;
    border-width: 1px;
    border-style: solid;
    border-color: white;
    border-radius: 50%;
    position: absolute;
    height: 226px;
    width: 226px;
    top: 50%;
    left: 50%;
    margin-left: -113px;
    margin-top: -113px;
}

最后一件事是调整JavaScript:

<script>
    $(document).ready(function() {
        $("button").click(function() {
            $('.earth-lines').toggle();
        });
    });
</script>

在这种情况下,它会被切换,并且看起来就像您想要的那样。这是一个小提琴:http : //jsfiddle.net/x3ybjd0f/1/

PS奇妙的想法和实现,我喜欢;)

更新

如何修复太阳。

在您的代码中 <img class="sun" src="5.png">

根据您的评论,图片的链接是http://toms-storage.tk/5.png

所以正确的代码是 <img class="sun" src="http://toms-storage.tk/5.png">

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

无法在我的太阳系模型上获得正确的轨道

来自分类Dev

OpenGL C ++-太阳系

来自分类Dev

太阳系模型动态壁纸

来自分类Dev

N 体重力/太阳系 Javascript 模拟

来自分类Dev

OpenGL 中的太阳系,相机位置

来自分类Dev

随机太阳系模拟碰撞检测问题

来自分类Dev

可以给我一些关于太阳系的源代码示例(android opengl,opengl)

来自分类Dev

就尺寸和质量而言,是否可以进行逼真的n体太阳系仿真?

来自分类Dev

太阳系模拟器物理集成问题(虚幻引擎4,C ++)

来自分类Dev

为什么太阳系的这种数值积分会继续运行?(麻省理工学院课程)

来自分类Dev

Kinect坐标系中心

来自分类Dev

OpenGL glScissors坐标系中心

来自分类Dev

链接无效的HTML / CSS轨道动画

来自分类Dev

将以地球为中心的坐标系转换为与切线平面对齐的坐标系?

来自分类Dev

HTML中的中心徽标

来自分类Dev

CSS / HTML中心框

来自分类Dev

中心表单HTML CSS

来自分类Dev

如何在锁定屏幕/控制中心上更改轨道位置?

来自分类Dev

用HTML轨道实现simple_form label_method

来自分类Dev

按中心放置HTML元素

来自分类Dev

页面HTML中的中心表

来自分类Dev

在页面中心以html打印文本

来自分类Dev

div内的HTML中心元素

来自分类Dev

iOS UITextView HTML:中心图像

来自分类Dev

太阳路径的计算

来自分类Dev

使图像在html中对齐屏幕中心

来自分类Dev

HTML数字输入中的中心文本

来自分类Dev

中心HTML表格单元格内容

来自分类Dev

中间img和菜单上的HTML中心