-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added solar-system animation (#2326)
- Loading branch information
Showing
5 changed files
with
185 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
body { | ||
margin: 0; | ||
overflow: hidden; | ||
background-color: #000; | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
height: 100vh; | ||
} | ||
stars { | ||
position: fixed; | ||
top: 0; | ||
left: 0; | ||
width: 100%; | ||
height: 100%; | ||
z-index: -1; | ||
} | ||
|
||
.star { | ||
position: absolute; | ||
width: 2px; | ||
height: 2px; | ||
background-color: white; | ||
opacity: 0.5; | ||
animation: twinkle 1s infinite; | ||
background: url('star.png') no-repeat center center/contain; | ||
|
||
} | ||
|
||
@keyframes twinkle { | ||
0% { opacity: 1; } | ||
50% { opacity: 0; } | ||
100% { opacity: 1; } | ||
} | ||
.solar-system { | ||
position: absolute; | ||
top: 50%; | ||
left: 50%; | ||
transform: translate(-50%, -50%); | ||
} | ||
|
||
.sun, | ||
.planet { | ||
width: 60px; | ||
height: 60px; | ||
background-color: #f39c12; | ||
border-radius: 50%; | ||
position: absolute; | ||
} | ||
|
||
.sun { | ||
background-color: #f39c12; | ||
} | ||
|
||
.mercury { | ||
background-color: #bdc3c7; | ||
top: -20px; | ||
left: 0; | ||
animation: planet-revolution 4s infinite linear; | ||
} | ||
|
||
.venus { | ||
background-color: #d35400; | ||
top: -40px; | ||
left: 70px; | ||
animation: planet-revolution 7s infinite linear; | ||
} | ||
|
||
.earth { | ||
background-color: #3498db; | ||
top: -60px; | ||
left: 140px; | ||
animation: planet-revolution 12s infinite linear; | ||
} | ||
|
||
.mars { | ||
background-color: #e74c3c; | ||
top: -80px; | ||
left: 210px; | ||
animation: planet-revolution 20s infinite linear; | ||
} | ||
|
||
.orbit { | ||
position: absolute; | ||
top: 50%; | ||
left: 50%; | ||
transform: translate(-50%, -50%); | ||
|
||
} | ||
|
||
.mercury-orbit { | ||
width: 40px; | ||
height: 40px; | ||
animation: orbit-rotation 4s infinite linear; | ||
} | ||
|
||
.venus-orbit { | ||
width: 100px; | ||
height: 100px; | ||
animation: orbit-rotation 7s infinite linear; | ||
} | ||
|
||
.earth-orbit { | ||
width: 160px; | ||
height: 160px; | ||
animation: orbit-rotation 12s infinite linear; | ||
} | ||
|
||
.mars-orbit { | ||
width: 220px; | ||
height: 220px; | ||
animation: orbit-rotation 20s infinite linear; | ||
} | ||
|
||
|
||
|
||
@keyframes planet-revolution { | ||
from { | ||
transform: rotate(0deg); | ||
} | ||
to { | ||
transform: rotate(360deg); | ||
} | ||
} | ||
|
||
@keyframes orbit-rotation { | ||
from { | ||
transform: rotate(0deg); | ||
} | ||
to { | ||
transform: rotate(360deg); | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<link rel="stylesheet" href="solar_system.css"> | ||
</head> | ||
<body> | ||
<div class="solar-system"> | ||
<div class="sun"></div> | ||
<div class="orbit mercury-orbit"> | ||
<div class="planet mercury"></div> | ||
</div> | ||
<div class="orbit venus-orbit"> | ||
<div class="planet venus"></div> | ||
</div> | ||
<div class="orbit earth-orbit"> | ||
<div class="planet earth"></div> | ||
</div> | ||
<div class="orbit mars-orbit"> | ||
<div class="planet mars"></div> | ||
</div> | ||
</div> | ||
<div class="stars"></div> | ||
<script> | ||
function createRandomStars() { | ||
const numberOfStars = 100; | ||
const starsContainer = document.querySelector('.stars'); | ||
|
||
for (let i = 0; i < numberOfStars; i++) { | ||
const star = document.createElement('div'); | ||
star.className = 'star'; | ||
star.style.left = `${Math.random() * 100}vw`; | ||
star.style.top = `${Math.random() * 100}vh`; | ||
star.style.width = `${Math.random() * 80}px`; | ||
star.style.height = star.style.width; | ||
const twinklingTime = Math.random() * 5 + 0.5; | ||
star.style.animation = `twinkle ${twinklingTime}s infinite`; | ||
starsContainer.appendChild(star); | ||
} | ||
} | ||
createRandomStars(); | ||
</script> | ||
</body> | ||
</html> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters