Skip to content

Instantly share code, notes, and snippets.

@Hong-been
Created March 10, 2022 19:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Hong-been/c9bc56ced924745e875fa197d38e69f3 to your computer and use it in GitHub Desktop.
Save Hong-been/c9bc56ced924745e875fa197d38e69f3 to your computer and use it in GitHub Desktop.
CSS Twinkling Stars
for (var i = 0; i < 100; i++) {
var star = '<div class="star" style="animation: twinkle '+((Math.random()*5) + 5)+'s linear '+((Math.random()*5) + 5)+'s infinite; top: '+Math.random()*$(window).height()+'px; left: '+Math.random()*$(window).width()+'px;"></div>';
$('body').append(star);
}
<script src="https://code.jquery.com/jquery-2.2.4.min.js"></script>
body {
background: black;
}
.star {
position: absolute;
width: 2px;
height: 2px;
background: rgba(255,255,255,0.0);
border-radius: 5px;
}
@keyframes twinkle {
0% {
transform: scale(1, 1);
background: rgba(255,255,255,0.0);
animation-timing-function: ease-in;
}
60% {
transform: scale(0.8, 0.8);
background: rgba(255,255,255,1);
animation-timing-function: ease-out;
}
80% {
background: rgba(255,255,255,0.00);
transform: scale(1, 1);
}
100% {
background: rgba(255,255,255,0.0);
transform: scale(1, 1);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment