在我的太陽系模型中,當您點擊「切換軌道」時,它會顯示所有熟悉的行星地球的軌道,但您注意到這個環沒有居中在行星的中間,只能在外面它,我會怎麼做,所以它會在中間?太陽系軌道html中心
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>
謝謝xD但是隨着我的OCD行事起來,你能幫助我在地球中心獲得線路並且軌道線路開始隱藏嗎?哦,你知道爲什麼太陽被這樣壓扁嗎? – user4191887 2014-12-07 02:44:47
太陽沒有被看到,因爲一個適當的圖像的URL 5.png不存在代碼 – 2014-12-07 02:48:48
@ user4191887我已經更新了css代碼,以最初隱藏線和中心看起來像它的中間' .earth'。太陽不在那裏,因爲太陽的URL不正確 - 你可能在本地有文件。 – 2014-12-07 02:50:49