Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Faded border loading spinner in CSS

Tags:

css

How can I make the last part of the spinner lighter (ie. fading):

	
#loader-wrapper {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1000;
}
#loader {
    display: block;
    position: relative;
    left: 50%;
    top: 50%;
    width: 150px;
    height: 150px;
    margin: -75px 0 0 -75px;
    border-radius: 50%;
    border: 5px solid transparent;
    border-top-color: #aaa;
    border-right-color: #aaa;    
    animation: spin 2s linear infinite;
}
 
@keyframes spin {
    0%   {
        transform: rotate(0deg);
    }
    100% {
        transform: rotate(360deg);
    }
}
<div id="loader-wrapper">
  <div id="loader"></div>
</div>

I tried using gradient but it converts it to a square

like image 869
Cornwell Avatar asked Dec 27 '16 21:12

Cornwell


1 Answers

You can apply the gradient to a pseudo-element like so:

#loader-wrapper {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 1000;
}
#loader {
  display: block;
  position: relative;
  left: 50%;
  top: 50%;
  width: 150px;
  height: 150px;
  margin: -75px 0 0 -75px;
  border-radius: 50%;
  border: 5px solid transparent;
  border-top-color: #aaa;
  border-right-color: #aaa;
  animation: spin 2s linear infinite;
}
#loader::after {
  content: '';
  width: 85%;
  height: 85%;
  background: linear-gradient(45deg, rgba(255, 255, 255, 1) 0%, rgba(255, 255, 255, 1) 40%, rgba(255, 255, 255, 0.7) 60%, rgba(255, 255, 255, 0) 100%);
  position: absolute;
  top: 0;
  left: 0;
  transform: translate(-5%, -5%);
}
@keyframes spin {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}
<div id="loader-wrapper">
  <div id="loader"></div>
</div>
like image 194
Ricky Avatar answered Sep 21 '22 17:09

Ricky