Skip to content

Instantly share code, notes, and snippets.

@troyericg
Last active July 6, 2016 16:10
Show Gist options
  • Save troyericg/3a9d51a911e6c807ea98ec4593e67063 to your computer and use it in GitHub Desktop.
Save troyericg/3a9d51a911e6c807ea98ec4593e67063 to your computer and use it in GitHub Desktop.
css gif with sprite

A fork/copy of Ben Welsh's code, which is a demonstration of how to create a GIF-like animation using only CSS. The only modification I've made is to use a sprite instead of multiple images.

<!DOCTYPE html>
<meta charset="utf-8">
<head>
<style type="text/css">
@-webkit-keyframes fadeOut {
25% {
opacity: 1;
}
50% {
opacity: 0;
}
}
@keyframes fadeOut {
25% {
opacity: 1;
}
50% {
opacity: 0;
}
}
ul {
list-style: none;
padding-left: 0;
}
.gif-container {
position: absolute;
top: 0;
right: 0;
left: 0;
width: 100%;
bottom: 0;
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-pack: center;
-ms-flex-pack: center;
justify-content: center;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
}
.gif-container .inner {
width: 70vh;
height: 70vh;
max-width: 45vw;
max-height: 45vw;
display: block;
margin-left: auto;
margin-right: auto;
}
.gif-container .inner li {
width: 70vh;
height: 70vh;
max-width: 45vw;
max-height: 45vw;
background-repeat: no-repeat;
background-size: cover;
background-position: 0% 0%; /* percents: 0% 0%; 33.32% 0%; 66.725% 0%; 100% 0%; || pixels: 0px 0px; -566px 0px; -1133px 0px; -1699px 0px; */
position: absolute;
opacity: 0;
-webkit-animation: fadeOut 8s infinite both;
animation: fadeOut 8s infinite both;
background-image: url("http://troyericgriggs.com/images/misc/test_la-me-year-in-focus-2015.jpg");
}
.gif-container .inner li:nth-child(2) {
-webkit-animation-delay: 2s;
animation-delay: 2s;
background-position: 33.32% 0%;
}
.gif-container .inner li:nth-child(3) {
-webkit-animation-delay: 4s;
animation-delay: 4s;
background-position: 66.725% 0%;
}
.gif-container .inner li:nth-child(4) {
-webkit-animation-delay: 6s;
animation-delay: 6s;
background-position: 100% 0%;
}
.gif-container figure {
width: 34rem;
display: block;
margin-left: 5rem;
margin-right: auto;
}
.gif-container span {
position: absolute;
top: 5rem;
left: 0;
}
</style>
</head>
<body>
<div id="graphic">
<div class="gif-container">
<ul class="inner">
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
</ul>
</div>
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment