April 30, 2015

Material Design Preloader

Material Design Preloader

A CSS3 only solution that recreates the Material Design preloader without any JavaScript or jQuery. You should set aria-busy to false when your stuff is loaded.

HTML

<header>
  <div aria-busy="true" aria-label="Loading, please wait." role="progressbar"></div>
</header>

CSS

header [role="progressbar"][aria-busy="true"] {
  position: absolute;
  top: 0;
  left: 0;
  padding-top: 8px;
  width: 100%;
  background-color: #159756;
  -webkit-animation: preloader-background linear 3.5s infinite;
  animation: preloader-background linear 3.5s infinite;
}

header [role="progressbar"][aria-busy="true"]::before,
header [role="progressbar"][aria-busy="true"]::after {
  display: block;
  position: absolute;
  top: 0;
  z-index: 2;
  width: 0;
  height: 8px;
  background: #afa;
  -webkit-animation: preloader-front linear 3.5s infinite;
  animation: preloader-front linear 3.5s infinite;
  content: '';
}

header [role="progressbar"][aria-busy="true"]::before {
  right: 50%;
}

header [role="progressbar"][aria-busy="true"]::after {
  left: 50%;
}

@-webkit-keyframes preloader-background {
  0%, 24.9% {
    background-color: #159756;
  }
  25%,
  49.9% {
    background-color: #da4733;
  }
  50%,
  74.9% {
    background-color: #3b78e7;
  }
  75%,
  100% {
    background-color: #fdba2c;
  }
}

@keyframes preloader-background {
  0%, 24.9% {
    background-color: #159756;
  }
  25%,
  49.9% {
    background-color: #da4733;
  }
  50%,
  74.9% {
    background-color: #3b78e7;
  }
  75%,
  100% {
    background-color: #fdba2c;
  }
}

@-webkit-keyframes preloader-front {
  0% {
    width: 0;
    background-color: #da4733;
  }
  24.9% {
    width: 50%;
    background-color: #da4733;
  }
  25% {
    width: 0;
    background-color: #3b78e7;
  }
  49.9% {
    width: 50%;
    background-color: #3b78e7;
  }
  50% {
    width: 0;
    background-color: #fdba2c;
  }
  74.9% {
    width: 50%;
    background-color: #fdba2c;
  }
  75% {
    width: 0%;
    background-color: #159756;
  }
  100% {
    width: 50%;
    background-color: #159756;
  }
}

@keyframes preloader-front {
  0% {
    width: 0;
    background-color: #da4733;
  }
  24.9% {
    width: 50%;
    background-color: #da4733;
  }
  25% {
    width: 0;
    background-color: #3b78e7;
  }
  49.9% {
    width: 50%;
    background-color: #3b78e7;
  }
  50% {
    width: 0;
    background-color: #fdba2c;
  }
  74.9% {
    width: 50%;
    background-color: #fdba2c;
  }
  75% {
    width: 0%;
    background-color: #159756;
  }
  100% {
    width: 50%;
    background-color: #159756;
  }
}

* {
  box-sizing: border-box;
}

p {
  font-family: Avenir Next, Helvetica Neue, Helvetica, Arial, sans-serif;
  padding: 5px;
}

header {
  position: relative;
  width: 100%;
  height: 60px;
  box-shadow: 0 2px 2px rgba(0, 0, 0, 0.2);
  background-color: #fff;
}
demo

No comments:

Post a Comment

Popular Posts

Views