Skip to content

Instantly share code, notes, and snippets.

@ghengeveld
Last active February 11, 2019 12:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ghengeveld/2d7e8ea5d11973de38815a0cbaf7bf72 to your computer and use it in GitHub Desktop.
Save ghengeveld/2d7e8ea5d11973de38815a0cbaf7bf72 to your computer and use it in GitHub Desktop.
Styled loading bar animation
import styled, { keyframes } from "styled-components"
const slide = keyframes`
0% { left: -35%; right: 100%; }
60% { left: 100%; right: -90%; }
100% { left: 100%; right: -90%; }
`
const chase = keyframes`
0% { left: -200%; right: 100%; }
60% { left: 107%; right: -8%; }
100% { left: 107%; right: -8%; }
`
const Loading = styled.div`
display: inline-block;
position: relative;
background: #ddd;
background-clip: padding-box;
border-radius: 2em;
width: ${props => props.width || "100%"};
height: ${props => props.height || "0.6em"};
overflow: hidden;
&::before,
&::after {
content: "";
position: absolute;
top: 0;
left: 0;
bottom: 0;
will-change: left, right;
background: #000;
background-clip: padding-box;
border-radius: 2em;
opacity: 0.1;
}
&::before {
animation: ${slide} 3s cubic-bezier(0.65, 0.815, 0.735, 0.395) infinite;
}
&::after {
animation: ${chase} 3s cubic-bezier(0.165, 0.84, 0.44, 1) infinite;
animation-delay: 1.5s;
}
`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment