Streaming live at 10am (PST)

Rotating text using CSS animations


#1

Hi! I want to create a sentence, with one part that continually changes. For example, the sentence would be 'I am' and the noun following 'am' would keep changing to something different from a list. Here is an example: http://tympanus.net/Tutorials/CSS3RotatingWords/

Am wondering if this is possible in Webflow and if it is, how to do it. I found a CSS3 animation tutorial but not sure how to replicate this in webflow: http://tympanus.net/codrops/2012/04/17/rotating-words-with-css-animations/

Thanks!


#2

Hi there @Amirah, it sure is possible smile It is a nice effect. Here is a basic example of this implemented in Webflow:

http://acme-widgets.webflow.com/rotating-words-demo-css-demo

Instruction:

  1. Create an embed widget on your page in a section, and paste the html markup from the codrops page, this is the Sections and H2 header etc from the original codrops page:

    http://tympanus.net/codrops/2012/04/17/rotating-words-with-css-animations

Make sure to copy the sample code, in the section called "The Markup" into your embed widget.

You can update the elements in the html markup to suit your purpose. Next, you will want to copy the complete CSS below, into the HEAD panel of the Custom Code section of Site Settings:

<style>

.rw-wrapper{
	width: 80%;
	position: relative;
	margin: 110px auto 0 auto;
	font-family: 'Bree Serif';
	padding: 10px;
}
.rw-sentence{
	margin: 0;
	text-align: left;
	text-shadow: 1px 1px 1px rgba(255,255,255,0.8);
}
.rw-sentence span{
	color: #444;
	font-size: 200%;
	font-weight: normal;
}
.rw-words{
	display: inline;
	text-indent: 10px;
}
.rw-words-1 span{
	position: absolute;
	opacity: 0;
	overflow: hidden;
	color: #6b969d;
	-webkit-animation: rotateWord 18s linear infinite 0s;
	-ms-animation: rotateWord 18s linear infinite 0s;
	animation: rotateWord 18s linear infinite 0s;
}
.rw-words-1 span:nth-child(2) { 
    -webkit-animation-delay: 3s; 
	-ms-animation-delay: 3s; 
	animation-delay: 3s; 
	color: #6b889d;
}
.rw-words-1 span:nth-child(3) { 
    -webkit-animation-delay: 6s; 
	-ms-animation-delay: 6s; 
	animation-delay: 6s; 
	color: #6b739d;	
}
.rw-words-1 span:nth-child(4) { 
    -webkit-animation-delay: 9s; 
	-ms-animation-delay: 9s; 
	animation-delay: 9s; 
	color: #7a6b9d;
}
.rw-words-1 span:nth-child(5) { 
    -webkit-animation-delay: 12s; 
	-ms-animation-delay: 12s; 
	animation-delay: 12s; 
	color: #8d6b9d;
}
.rw-words-1 span:nth-child(6) { 
    -webkit-animation-delay: 15s; 
	-ms-animation-delay: 15s; 
	animation-delay: 15s; 
	color: #9b6b9d;
}
@-webkit-keyframes rotateWord {
    0% { opacity: 0; }
    2% { opacity: 0; -webkit-transform: translateY(-30px); }
	5% { opacity: 1; -webkit-transform: translateY(0px);}
    17% { opacity: 1; -webkit-transform: translateY(0px); }
	20% { opacity: 0; -webkit-transform: translateY(30px); }
	80% { opacity: 0; }
    100% { opacity: 0; }
}
@-ms-keyframes rotateWord {
    0% { opacity: 0; }
    2% { opacity: 0; -ms-transform: translateY(-30px); }
	5% { opacity: 1; -ms-transform: translateY(0px);}
    17% { opacity: 1; -ms-transform: translateY(0px); }
	20% { opacity: 0; -ms-transform: translateY(30px); }
	80% { opacity: 0; }
    100% { opacity: 0; }
}
@keyframes rotateWord {
    0% { opacity: 0; }
    2% { opacity: 0; -webkit-transform: translateY(-30px); transform: translateY(-30px); }
	5% { opacity: 1; -webkit-transform: translateY(0px); transform: translateY(0px);}
    17% { opacity: 1; -webkit-transform: translateY(0px); transform: translateY(0px); }
	20% { opacity: 0; -webkit-transform: translateY(30px); transform: translateY(30px); }
	80% { opacity: 0; }
    100% { opacity: 0; }
}
@media screen and (max-width: 768px){
	.rw-sentence { font-size: 18px; }
}
@media screen and (max-width: 320px){
	.rw-sentence { font-size: 9px; }
}

</style>

If you want to change the styles of the different elements that this code uses, you can do so also within this custom CSS. I have not tried out yet, what happens if the elements are created with Webflow and just assigned the correct class names, but I will do that next. If that works, then you do not even need to put in the custom embed code, you can just create the same structure as the html markup that codrops provided, and give the same class names to those elements as used in the example. Once you copy the CSS styles above to your HEAD section, then you can try to create the elements also in Webflow with same structure, and assign the class names... the working example in Webflow that I made, is using just the html markup, pasted into the Embed widget.

I hope that helps ! Cheers!


How to use code from codrops?
#3