-
-
Save ryanlucas/9410abd41a5edab568ece46e5fe4d57b to your computer and use it in GitHub Desktop.
LoadingAnimation
This file contains 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
LoadingAnimation | |
Loading | |
next -> AlmostDone | |
AlmostDone | |
next -> Finished | |
Finished | |
next -> App | |
App |
This file contains 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
function add_styles(css_str){ | |
const StyleID = 'my_stylez'; | |
let $s = document.querySelector('#' + StyleID); | |
if(null === $s){ | |
$s = document.createElement('style'); | |
$s.id = StyleID | |
document.head.appendChild($s) | |
} | |
$s.innerText = css_str; | |
} | |
//Define CSS animations | |
add_styles(` | |
.ball { | |
margin: 100px auto; | |
width: 20px; | |
height: 20px; | |
animation-name: spinning; | |
animation-iteration-count: infinite; | |
animation-timing-function: linear; | |
} | |
[data-state='Loading'] { | |
background-color: red; | |
animation-duration: 4s; | |
} | |
[data-state='AlmostDone'] { | |
background-color: orange; | |
animation-duration: 1s; | |
} | |
[data-state='Finished'] { | |
background-color: gray; | |
width: 200px; | |
height: 200px; | |
transition: all 1s; | |
animation-name: spinning-finish; | |
animation-iteration-count: infinite; | |
animation-timing-function: linear; | |
animation-duration: 1s; | |
animation-iteration-count: 2; | |
} | |
[data-state='App'] { | |
margin: 0 auto; | |
width: 80%; | |
height: 80%; | |
background-color: lightGray; | |
border: 5px solid black; | |
transition: all 500ms; | |
} | |
@keyframes spinning { | |
from { transform:rotate(0deg); } | |
to { transform:rotate(360deg); } | |
} | |
@keyframes spinning-finish { | |
from { transform:rotate(0deg); } | |
to { transform:rotate(360deg); } | |
} | |
`); | |
function render(model){ | |
const name = model.active_states[0].name; | |
return $('div', {className: 'ball', 'data-state': name}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment