Skip to content

Instantly share code, notes, and snippets.

@richleach
Created May 7, 2020 20:38
Show Gist options
  • Save richleach/21a2d008f2b586b12a0ab681bb0f9c2b to your computer and use it in GitHub Desktop.
Save richleach/21a2d008f2b586b12a0ab681bb0f9c2b to your computer and use it in GitHub Desktop.
CSS: Animations introduced with basic syntax and functional CSS. Some commented code for you to use in your next CSS animation.
<html>
<head>
<meta charset="UTF-8">
<title>SANDBOX</title>
<style type="text/css">
.heading {
color: darkblue;
font-size: 15px;
/*transition-property: font-size;
transition-delay: 1s;
transition-duration: 0.5s;
transition-timing-function: ease-in; */
transition: all 1s ease 1s;
}
.heading:hover {
color: green;
font-size: 10px;
}
/* simple animation, starts and stops
.box {
width: 50px;
height: 50px;
background: red;
border: 1px solid black;
animation-name: grow;
animation-duration: 2s;
}
@keyframes grow {
0% {width: 50px; height: 50px; background: red;} //this could be "from"
50% {width: 100px; height: 50px; background: blue;}
100% {width: 100px; height: 100px; background: green;} //this could be "to"
}
*/
/* more advanced animation, runs forever thanks to animation-iteration-count property
.box {
width: 100px;
height: 100px;
background: blue;
border: 1px solid black;
animation-name: grow;
animation-duration: 1s;
animation-timing-function: ease-in;
animation-delay: 1s;
animation-iteration-count: infinite;
animation-direction: alternate;
animation-fill-mode: both;
}
@keyframes grow {
from {width: 100px; height: 100px; background: blue;}
to {width: 10px; height: 10px; background: red;}
}
*/
/* */
/* long hand way to write this animation out....
.box {
width: 100px;
height: 100px;
background: blue;
border: 1px solid black;
animation-name: grow;
animation-duration: 1s;
animation-timing-function: ease-in;
animation-delay: 1s;
animation-iteration-count: infinite;
animation-direction: alternate;
animation-fill-mode: both;
}
@keyframes grow {
from {width: 100px; height: 100px; background: blue;}
to {width: 10px; height: 10px; background: red;}
}
*/
/* short hand way to write out the above animation */
.box {
width: 100px;
height: 100px;
background: blue;
border: 1px solid black;
/* animation-name: grow;
animation-duration: 1s;
animation-timing-function: ease-in;
animation-delay: 1s;
animation-iteration-count: 4;
animation-direction: alternate; */
animation-fill-mode: both;
animation: grow 1s ease-in 1s 4 alternate;
}
@keyframes grow {
from {width: 100px; height: 100px; background: blue;}
to {width: 10px; height: 10px; background: red;}
}
</style>
</head>
<body>
<h1 class="heading">Hover over me!</h1>
<div class="box"></div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment