Hey all,
I made a simple (S)CSS based loader animation with a success end point. Thought I would share here in case anyone wishes to use it and to ask for some feedback/ways to improve it.
I know there are multiple libraries which do this sort of thing, just wanted to make one myself to learn and then get feedback on.
Some code:
SCSS
.loader {
position: absolute;
content: '';
top: calc(50% - 2.5rem);
left: calc(50% - 2.5rem);
width: 5rem;
height: 5rem;
border: 5px solid lightGreen;
border-radius: 50%;
animation: spin 1s linear infinite;
overflow: hidden;
transition: 0.3s;
background: lightGreen;
box-shadow: 0rem 0rem 0.6rem rgba(0,0,0,0.3);
.line-long {
height: 7px;
width: 2.5rem;
position: absolute;
top: 65%;
left: 44%;
background-color: green;
transform: rotate(-45deg);
transform-origin: 0% 50%;
border-radius: 5px;
animation: baseGrow 1s;
}
.line-short {
height: 7px;
width: 1.5rem;
position: absolute;
top: 65%;
left: 50%;
background-color: green;
transform: rotate(-135deg);
transform-origin: 0% 50%;
border-radius: 5px;
animation: tipGrow 1s;
}
}
@keyframes spin {
0% {
transform: rotate(0deg);
border-top: 5px solid darkGreen;
}
100% {
transform: rotate(360deg);
border-top: 5px solid darkGreen;
}
}
@keyframes tipGrow {
0% {
width: 0px;
left: 0;
top: 0;
}
25% {
width: 0px;
left: 0;
top: 0;
}
50% {
top: 0%;
left: 0%;
width: 0;
}
75% {
top: 0%;
left: 0%;
width: 0rem;
}
100% {
top: 65%;
left: 50%;
width: 1.5rem;
}
}
@keyframes baseGrow {
0% {
width: 0;
}
90% {
width: 0;
}
100% {
width: 2.5rem;
}
}
@keyframes pop {
0% {
transform: scale(1);
}
80% {
transform: scale(1);
}
100% {
transform: scale(1.1);
}
}
Javascript
const tickBase = document.createElement('span');
const tickFoot = document.createElement('span');
const loader = document.querySelector('.loader');
tickBase.classList.add('line-long');
tickFoot.classList.add('line-short');
function finish () {
loader.appendChild(tickBase);
loader.appendChild(tickFoot);
loader.style.animation = 'none';
loader.style.animation = 'pop 1.2s ease-in-out';
}
setTimeout(() => finish(), 2000);
HTML
<span class="loader">
</span>
JSFiddle: https://jsfiddle.net/makingstuffs/cos2zbhd/
Thanks in advance