Skip to content

Instantly share code, notes, and snippets.

@oloman
Created May 9, 2012 22:35
Show Gist options
  • Save oloman/2649418 to your computer and use it in GitHub Desktop.
Save oloman/2649418 to your computer and use it in GitHub Desktop.
Rotating Words with CSS Animations
/* Rotating Words with CSS Animations */
/* Codrops: http://goo.gl/utC04 */
@font-face {
font-family: 'Open Sans Condensed';
font-style: normal;
font-weight: 700;
src: local('Open Sans Condensed Bold'), local('OpenSans-CondensedBold'), url('http://themes.googleusercontent.com/static/fonts/opensanscondensed/v6/gk5FxslNkTTHtojXrkp-xONSK5BxN3NFS4EJkViHIqo.woff') format('woff');
}
.rw-wrapper{
width: 80%;
position: relative;
margin: 0px auto 0 auto;
font-family: 'Open Sans Condensed';
padding: 10px;
height: 300px;
overflow: hidden;
background: #ccc;
}
.rw-sentence{
margin: 0;
text-align: left;
text-shadow: 1px 1px 1px rgba(255,255,255,0.8);
}
.rw-sentence span{
color: #444;
white-space: nowrap;
font-size: 200%;
font-weight: normal;
}
.rw-words{
display: inline;
text-indent: 10px;
}
.rw-words-1 span{
position: absolute;
opacity: 0;
overflow: hidden;
color: #888;
-webkit-transform-origin: 10% 75%;
-moz-transform-origin: 10% 75%;
-ms-transform-origin: 10% 75%;
-o-transform-origin: 10% 75%;
transform-origin: 10% 75%;
-webkit-animation: rotateWord 18s linear infinite 0s;
-moz-animation: rotateWord 18s linear infinite 0s;
-o-animation: rotateWord 18s linear infinite 0s;
-ms-animation: rotateWord 18s linear infinite 0s;
animation: rotateWord 18s linear infinite 0s;
}
.rw-words span:nth-child(2) {
-webkit-animation-delay: 3s;
-moz-animation-delay: 3s;
-o-animation-delay: 3s;
-ms-animation-delay: 3s;
animation-delay: 3s;
color: #6b889d;
}
.rw-words span:nth-child(3) {
-webkit-animation-delay: 6s;
-moz-animation-delay: 6s;
-o-animation-delay: 6s;
-ms-animation-delay: 6s;
animation-delay: 6s;
color: #99dd00;
}
.rw-words span:nth-child(4) {
-webkit-animation-delay: 9s;
-moz-animation-delay: 9s;
-o-animation-delay: 9s;
-ms-animation-delay: 9s;
animation-delay: 9s;
color: #cc0000;
}
.rw-words span:nth-child(5) {
-webkit-animation-delay: 12s;
-moz-animation-delay: 12s;
-o-animation-delay: 12s;
-ms-animation-delay: 12s;
animation-delay: 12s;
color: #8d6b9d;
}
.rw-words span:nth-child(6) {
-webkit-animation-delay: 15s;
-moz-animation-delay: 15s;
-o-animation-delay: 15s;
-ms-animation-delay: 15s;
animation-delay: 15s;
color: #ee00cc;
}
@-webkit-keyframes rotateWord {
0% { opacity: 0; }
5% { opacity: 1; }
17% { opacity: 1; -webkit-transform: rotate(0deg); }
19% { opacity: 1; -webkit-transform: rotate(98deg); }
21% { opacity: 1; -webkit-transform: rotate(86deg); }
23% { opacity: 1; -webkit-transform: translateY(85px) rotate(83deg); }
25% { opacity: 0; -webkit-transform: translateY(170px) rotate(80deg); }
80% { opacity: 0; }
100% { opacity: 0; }
}
@-moz-keyframes rotateWord {
0% { opacity: 0; }
5% { opacity: 1; }
17% { opacity: 1; -moz-transform: rotate(0deg); }
19% { opacity: 1; -moz-transform: rotate(98deg); }
21% { opacity: 1; -moz-transform: rotate(86deg); }
23% { opacity: 1; -moz-transform: translateY(85px) rotate(83deg); }
25% { opacity: 0; -moz-transform: translateY(170px) rotate(80deg); }
80% { opacity: 0; }
100% { opacity: 0; }
}
@-o-keyframes rotateWord {
0% { opacity: 0; }
5% { opacity: 1; }
17% { opacity: 1; -o-transform: rotate(0deg); }
19% { opacity: 1; -o-transform: rotate(98deg); }
21% { opacity: 1; -o-transform: rotate(86deg); }
23% { opacity: 1; -o-transform: translateY(85px) rotate(83deg); }
25% { opacity: 0; -o-transform: translateY(170px) rotate(80deg); }
80% { opacity: 0; }
100% { opacity: 0; }
}
@-ms-keyframes rotateWord {
0% { opacity: 0; }
5% { opacity: 1; }
17% { opacity: 1; -ms-transform: rotate(0deg); }
19% { opacity: 1; -ms-transform: rotate(98deg); }
21% { opacity: 1; -ms-transform: rotate(86deg); }
23% { opacity: 1; -ms-transform: translateY(85px) rotate(83deg); }
25% { opacity: 0; -ms-transform: translateY(170px) rotate(80deg); }
80% { opacity: 0; }
100% { opacity: 0; }
}
@keyframes rotateWord {
0% { opacity: 0; }
5% { opacity: 1; }
17% { opacity: 1; transform: rotate(0deg); }
19% { opacity: 1; transform: rotate(98deg); }
21% { opacity: 1; transform: rotate(86deg); }
23% { opacity: 1; transform: translateY(85px) rotate(83deg); }
25% { opacity: 0; transform: translateY(170px) rotate(80deg); }
80% { opacity: 0; }
100% { opacity: 0; }
}
@media screen and (max-width: 768px){
.rw-sentence { font-size: 18px; }
}
<!-- content to be placed inside <body>…</body> -->
<section class="rw-wrapper">
<h2 class="rw-sentence">
<span>La auténtica poesía es cómo</span>
<br />
<span>crear bellas mariposas</span>
<br />
<span>con un silencioso toque de</span>
<div class="rw-words rw-words-1">
<span>especias</span>
<span>colores</span>
<span>felicidad</span>
<span>asombro</span>
<span>azúcar</span>
<span>melancolía</span>
</div>
</h2>
</section>
<h2 class="rw-sentence-IE">
La auténtica poesía es cómo crear bellas mariposas con un silencioso toque de especias
</h2>
{"view":"separate","fontsize":"90","seethrough":"","prefixfree":"1","page":"all"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment