Login Button with Spinner

Animate to spinner once clicked

by mgoetzke

HTML

<div class="row">
  <button id="btn" onclick="this.className += ' in'">
    Sign In
    <div class="loader">Loading...</div>
  </button>
</div>

CSS

.row {
  width: 100%;
  position: relative;
  text-align: center;
}

.row button {
  overflow: hidden;
  display: inline-block;
  border-radius: 10px;
  min-width: 200px;
  min-height: 50px;
  border: 1px solid #aaa;
  transition: all 0.4s ease, font-size 0.2s, color 0.3s;
  font-family: Roboto;
  background: #039BE5;
  color: white;
  font-weight: 600;
  font-size: 20px;
  position: relative;
}

button > .loader {
  opacity: 0;
  transition: opacity 2s, width: 0s;
  width: 16px;
  position: absolute;
  margin: auto;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
}

button.in {
  background: #0277BD;
  font-size: 0px;
  min-width: 50px;
  border-radius: 50px;
  color: transparent;
}

button.in > .loader {
  opacity: 100;
  width: 16px;
}

.loader,
.loader:after {
  border-radius: 50%;
  width: 16px;
  height: 16px;
  xdisplay: block;
}

.loader {
  xmargin: 0px auto;
  font-size: 10px;
  position: relative;
  text-indent: -9999em;
  border-top: 2px solid rgba(255, 255, 255, 0.2);
  border-right: 2px solid rgba(255, 255, 255, 0.2);
  border-bottom: 2px solid rgba(255, 255, 255, 0.2);
  border-left: 2px solid #ffffff;
  -webkit-transform: translateZ(0);
  -ms-transform: translateZ(0);
  transform: translateZ(0);
  -webkit-animation: load8 1.1s infinite linear;
  animation: load8 1.1s infinite linear;
}

@-webkit-keyframes load8 {
  0% {
    -webkit-transform: rotate(0deg);
    transform: rotate(0deg);
  }
  100% {
    -webkit-transform: rotate(360deg);
    transform: rotate(360deg);
  }
}

@keyframes load8 {
  0% {
    -webkit-transform: rotate(0deg);
    transform: rotate(0deg);
  }
  100% {
    -webkit-transform: rotate(360deg);
    transform: rotate(360deg);
  }
}

JavaScript

function reset() {
  document.getElementById('btn').className = ''
}