Skip to content

Instantly share code, notes, and snippets.

@yuri-ktm
Created July 26, 2022 11:35
Show Gist options
  • Select an option

  • Save yuri-ktm/6d47d89476347ea1027905118d3f581f to your computer and use it in GitHub Desktop.

Select an option

Save yuri-ktm/6d47d89476347ea1027905118d3f581f to your computer and use it in GitHub Desktop.
CSS Loading Animation

CSS Loading Animation

A css loading animation which uses keyframes as well as SASS and Compass to position the dots around the edge of the circle. It also uses haml and prefix-free :)

A Pen by Hillary Thomas on CodePen.

License.

.container
.loading-overlay
.loading-anim
.border.out
.border.in
.border.mid
.circle
@import "compass/css3";
$blue: #0000FF;
$blue2:#BFBFFF;
$blue3: #7879FF;
input, select, textarea {
/* I want my default button style back */
font-size: 90%;
}
* {
box-sizing: border-box;
}
.container {
margin: 20px;
width: calc(100% - 40px);
height: auto;
}
.loading-overlay {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(255, 255, 255, 0);
transition: background-color .2s ease-out;
}
$loader-size: 200px;
$animation-length: 5s;
.loading-anim {
position: relative;
width: $loader-size;
height: $loader-size;
margin: auto;
perspective: 800px;
transform-style: preserve-3d;
transform: translateZ(-100px) rotateY(-90deg) rotateX(90deg) rotateZ(90deg) scale(.5);
opacity: 0;
transition: all .2s ease-out;
.circle {
width: 100%;
height: 100%;
$blue2:#BFBFFF;
animation: spin $animation-length linear infinite;
}
.border {
position: absolute;
border-radius: 50%;
border: 3px solid $blue;
}
$out: 70%;
.out {
top: (100% - $out) / 2;
left: (100% - $out) / 2;
width: $out;
height: $out;
border: 5px solid $blue2;
border-left-color: transparent;
border-right-color: transparent;
animation: spin 2s linear reverse infinite;
}
$in: 64%;
.in {
top: (100% - $in) / 2;
left: (100% - $in) / 2;
width: $in;
height: $in;
border: 5px solid $blue3;
border-top-color: transparent;
border-bottom-color: transparent;
animation: spin 2s linear infinite;
}
$mid: 20%;
.mid {
top: (100% - $mid) / 2;
left: (100% - $mid) / 2;
width: $mid;
height: $mid;
border: 5px solid $blue2;
border-left-color: transparent;
border-right-color: transparent;
animation: spin 0.51s linear infinite;
}
}
.loading .loading-anim {
transform: translateZ(0) rotateY(0deg) rotateX(0deg) rotateZ(0deg) scale(1);
opacity: 1;
}
.loading .loading-overlay {
background: rgba(255, 255, 255, .5);
}
$size: 20px;
@keyframes spin {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}
@keyframes jitter {
0% {
transform: scale(1, 1);
}
25% {
transform: scale(0.7, 0.7);
}
50% {
transform: scale(1, 1);
}
75% {
transform: scale(1.3, 1.3);
}
100% {
transform: scale(1, 1);
}
}
@keyframes fade-in-out {
0% {
opacity: 0.8;
}
25% {
opacity: 0.2;
}
75% {
opacity: 1;
}
100% {
opacity: 0.8;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment