A Pen by T. H. Doan on CodePen.
Created
March 10, 2022 19:21
-
-
Save Hong-been/c9bc56ced924745e875fa197d38e69f3 to your computer and use it in GitHub Desktop.
CSS Twinkling Stars
This file contains hidden or 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
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); | |
} |
This file contains hidden or 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
<script src="https://code.jquery.com/jquery-2.2.4.min.js"></script> |
This file contains hidden or 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
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