A Pen by Nate Wiley on CodePen.
Created
September 22, 2022 23:03
-
-
Save prabby/c99d60ff36524b6e4f9f9d20f35e7726 to your computer and use it in GitHub Desktop.
Particle Orb CSS
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
%div.wrap | |
-300.times do | |
%div.c |
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
// no js |
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
// best in chrome | |
$total: 300; // total particles | |
$orb-size: 100px; | |
$particle-size: 2px; | |
$time: 14s; | |
$base-hue: 0; // change for diff colors (180 is nice) | |
html, body { | |
height: 100%; | |
} | |
body { | |
background: black; | |
overflow: hidden; // no scrollbars.. | |
} | |
.wrap { | |
position: relative; | |
top: 50%; | |
left: 50%; | |
width: 0; | |
height: 0; | |
transform-style: preserve-3d; | |
perspective: 1000px; | |
animation: rotate $time infinite linear; // rotate orb | |
} | |
@keyframes rotate { | |
100% { | |
transform: rotateY(360deg) rotateX(360deg); | |
} | |
} | |
.c { | |
position: absolute; | |
width: $particle-size; | |
height: $particle-size; | |
border-radius: 50%; | |
opacity: 0; | |
} | |
@for $i from 1 through $total { | |
$z: (random(360) * 1deg); // random angle to rotateZ | |
$y: (random(360) * 1deg); // random to rotateX | |
$hue: ((40/$total * $i) + $base-hue); // set hue | |
.c:nth-child(#{$i}){ // grab the nth particle | |
animation: orbit#{$i} $time infinite; | |
animation-delay: ($i * .01s); | |
background-color: hsla($hue, 100%, 50%, 1); | |
} | |
@keyframes orbit#{$i}{ | |
20% { | |
opacity: 1; // fade in | |
} | |
30% { | |
transform: rotateZ(-$z) rotateY($y) translateX($orb-size) rotateZ($z); // form orb | |
} | |
80% { | |
transform: rotateZ(-$z) rotateY($y) translateX($orb-size) rotateZ($z); // hold orb state 30-80 | |
opacity: 1; // hold opacity 20-80 | |
} | |
100% { | |
transform: rotateZ(-$z) rotateY($y) translateX( ($orb-size * 3) ) rotateZ($z); // translateX * 3 | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment