Created
September 30, 2018 15:34
-
-
Save zerobias/efb5915af04e4db85cc60eecc63c4d58 to your computer and use it in GitHub Desktop.
animated css gears
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //@flow | |
| import * as React from 'react' | |
| import {render} from 'react-dom' | |
| import styled, {keyframes, css} from 'styled-components' | |
| export function run() { | |
| let devpage = document.querySelector('#devpage') | |
| if (!devpage) { | |
| devpage = document.createElement('div') | |
| const {body} = document | |
| if (!body) return | |
| body.appendChild(devpage) | |
| devpage.id = 'devpage' | |
| } | |
| render(<Gears />, devpage) | |
| } | |
| const Gears = () => ( | |
| <Container> | |
| <Gearbox> | |
| <Overlay /> | |
| <GearOne> | |
| <GearInner> | |
| <Bar /> | |
| <Bar /> | |
| <Bar /> | |
| </GearInner> | |
| </GearOne> | |
| <GearTwo> | |
| <GearInner> | |
| <Bar /> | |
| <Bar /> | |
| <Bar /> | |
| </GearInner> | |
| </GearTwo> | |
| <GearThree> | |
| <GearInner> | |
| <Bar /> | |
| <Bar /> | |
| <Bar /> | |
| </GearInner> | |
| </GearThree> | |
| <GearFour> | |
| <GearInner> | |
| <Bar /> | |
| <Bar /> | |
| <Bar /> | |
| <Bar /> | |
| <Bar /> | |
| <Bar /> | |
| </GearInner> | |
| </GearFour> | |
| </Gearbox> | |
| </Container> | |
| ) | |
| const clockwise = keyframes` | |
| 0% { | |
| transform: rotate(0deg); | |
| } | |
| 100% { | |
| transform: rotate(360deg); | |
| } | |
| ` | |
| const counterClockwise = keyframes` | |
| 0% { | |
| transform: rotate(0deg); | |
| } | |
| 100% { | |
| transform: rotate(-360deg); | |
| } | |
| ` | |
| const Bar = styled.div` | |
| &:nth-child(2) { | |
| transform: rotate(60deg); | |
| } | |
| &:nth-child(3) { | |
| transform: rotate(120deg); | |
| } | |
| &:nth-child(4) { | |
| transform: rotate(90deg); | |
| } | |
| &:nth-child(5) { | |
| transform: rotate(30deg); | |
| } | |
| &:nth-child(6) { | |
| transform: rotate(150deg); | |
| } | |
| ` | |
| const GearInner = styled.div` | |
| position: relative; | |
| height: 100%; | |
| width: 100%; | |
| background: #555; | |
| animation-iteration-count: infinite; | |
| border-radius: 30px; | |
| border: 1px solid rgba(255, 255, 255, 0.1); | |
| & ${Bar} { | |
| background: #555; | |
| height: 16px; | |
| width: 76px; | |
| position: absolute; | |
| left: 50%; | |
| margin-left: -38px; | |
| top: 50%; | |
| margin-top: -8px; | |
| border-radius: 2px; | |
| border-left: 1px solid rgba(255, 255, 255, 0.1); | |
| border-right: 1px solid rgba(255, 255, 255, 0.1); | |
| } | |
| ` | |
| const Gear = styled.div` | |
| position: absolute; | |
| height: 60px; | |
| width: 60px; | |
| box-shadow: 0px -1px 0px 0px #888888, 0px 1px 0px 0px black; | |
| border-radius: 30px; | |
| &:after { | |
| content: ''; | |
| position: absolute; | |
| height: 36px; | |
| width: 36px; | |
| border-radius: 36px; | |
| background: #111; | |
| top: 50%; | |
| left: 50%; | |
| margin-left: -18px; | |
| margin-top: -18px; | |
| z-index: 3; | |
| box-shadow: 0px 0px 10px rgba(255, 255, 255, 0.1), | |
| inset 0px 0px 10px rgba(0, 0, 0, 0.1), inset 0px 2px 0px 0px #090909, | |
| inset 0px -1px 0px 0px #888888; | |
| } | |
| ` | |
| const Overlay = styled.div` | |
| border-radius: 6px; | |
| content: ''; | |
| position: absolute; | |
| top: 0; | |
| left: 0; | |
| width: 100%; | |
| height: 100%; | |
| z-index: 10; | |
| box-shadow: inset 0px 0px 20px black; | |
| transition: background 0.2s; | |
| ` | |
| const Gearbox = styled.div` | |
| background: #111; | |
| height: 150px; | |
| width: 200px; | |
| position: relative; | |
| border: none; | |
| overflow: hidden; | |
| border-radius: 6px; | |
| box-shadow: 0px 0px 0px 1px rgba(255, 255, 255, 0.1); | |
| ` | |
| const large = css` | |
| height: 120px; | |
| width: 120px; | |
| border-radius: 60px; | |
| &:after { | |
| height: 96px; | |
| width: 96px; | |
| border-radius: 48px; | |
| margin-left: -48px; | |
| margin-top: -48px; | |
| } | |
| & ${GearInner} { | |
| border-radius: 60px; | |
| & ${Bar} { | |
| margin-left: -68px; | |
| width: 136px; | |
| } | |
| } | |
| ` | |
| const GearOne = styled(Gear)` | |
| top: 12px; | |
| left: 10px; | |
| ` | |
| const GearTwo = styled(Gear)` | |
| top: 61px; | |
| left: 60px; | |
| ` | |
| const GearThree = styled(Gear)` | |
| top: 110px; | |
| left: 10px; | |
| ` | |
| const GearFour = styled(Gear)` | |
| top: 13px; | |
| left: 128px; | |
| ${large}; | |
| ` | |
| const Container = styled.div` | |
| z-index: 1; | |
| position: absolute; | |
| top: 50%; | |
| left: 50%; | |
| margin-left: -100px; | |
| height: 150px; | |
| width: 200px; | |
| margin-top: -75px; | |
| &:hover { | |
| & ${GearOne} ${GearInner} { | |
| animation: ${counterClockwise} 1s 1 ease-in-out; | |
| } | |
| & ${GearTwo} ${GearInner} { | |
| animation: ${clockwise} 1s 1 ease-in-out; | |
| } | |
| & ${GearThree} ${GearInner} { | |
| animation: ${counterClockwise} 1s 1 ease-in-out; | |
| } | |
| & ${GearFour} ${GearInner} { | |
| animation: ${counterClockwise} 1s 1 ease-in-out; | |
| } | |
| } | |
| ` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment