<div class="wrapper">
<h3>[background-position]</h3>
<div class="loading-bg"></div>
<h3>[box-shadow]</h3>
<div class="loading-bs"></div>
</div>
@import url('https://fonts.googleapis.com/css2?family=Space+Mono:wght@700&display=swap');
$color: #ffcc33;
$bezier: cubic-bezier(0, 0.02, 0.21, 2.87);
body {
height: 100vh;
background-color: #fcfcfc;
display: flex;
justify-content: center;
align-items: center;
font-family: 'Space Mono', monospace;
h3 {
text-decoration: underline;
}
}
.wrapper {
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
}
// ---------------------
// use background-position
// ---------------------
$bg-size: 40px;
$bg-jump: 25%;
.loading-bg {
width: $bg-size * 4;
height: 80px;
margin-bottom: 20px;
background: radial-gradient(circle, $color 50%, transparent 50%),
radial-gradient(circle, $color 50%, transparent 50%),
radial-gradient(circle, $color 50%, transparent 50%);
background-repeat: no-repeat;
background-size: $bg-size $bg-size;
animation: bounce-bg 1.2s both infinite $bezier;
}
$part: 1 /6 * 100%;
@keyframes bounce-bg {
0%, 100%, #{$part*2}, #{$part*4} {
background-position: 0 50%, 50% 50%, 100% 50%;
}
#{$part*1} {
background-position: 0 $bg-jump, 50% 50%, 100% 50%;
}
#{$part*3} {
background-position: 0 50%, 50% $bg-jump, 100% 50%;
}
#{$part*5} {
background-position: 0 50%, 50% 50%, 100% $bg-jump;
}
}
// ---------------------
// use box-shadow
// ---------------------
$bs-size: 28px;
$distance1: $bs-size * 1;
$distance2: $bs-size * 3;
$distance3: $bs-size * 5;
$bs-jump: -$bs-size / 3;
.loading-bs {
width: $bs-size;
height: $bs-size;
border-radius: 50%;
margin: 24px auto;
box-shadow: $distance1 0 0 $color, $distance2 0 0 $color, $distance3 0 0 $color;
transform: translateX(-$distance2);
animation: bounce-bs 1.2s both infinite $bezier;
}
@keyframes bounce-bs {
0%, 100%, #{$part*2}, #{$part*4} {
box-shadow: $distance1 0 0 $color, $distance2 0 0 $color, $distance3 0 0 $color;
}
#{$part*1} {
box-shadow: $distance1 $bs-jump 0 $color, $distance2 0 0 $color, $distance3 0 0 $color;
}
#{$part*3} {
box-shadow: $distance1 0 0 $color, $distance2 $bs-jump 0 $color, $distance3 0 0 $color;
}
#{$part*5} {
box-shadow: $distance1 0 0 $color, $distance2 0 0 $color, $distance3 $bs-jump 0 $color;
}
}
View Compiled
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.