I'm trying to animate a single word using CSS and HTML. I want the word to fade in, stay visible and then fade out and after that, I want to continue with the next word.
I followed this tutorial (http://tympanus.net/codrops/2012/04/17/rotating-words-with-css-animations), but the problem is that I am unable to understand how to set the percentage of the duration in the #keyframes animation, because in the tutorial it's just written:
Our animations will run one cycle, meaning that each span will be shown once for three seconds, hence the delay value. The whole animation will run 6 (number of images) * 3 (appearance time) = 18 seconds. We will need to set the right percentage for the opacity value (or whatever makes the span appear). Dividing 6 by 18 gives us 0.333… which would be 33% for our keyframe step. Everything that we want to happen to the span needs to happen before that. So, after tweaking and seeing what fits best, we come up with the following animation for the first words
In my case, my whole animation is 16s long (because I have 4 words * 4s), so 4/16 = 0,25, that's why everything needs to happen before 25%.
Here is my animation code:
#keyframes rotateWord {
0% { opacity: 0; }
2% { opacity: 0; -webkit-transform: translateX(0px); transform: translateX(0px); }
5% { opacity: 1; -webkit-transform: translateX(0px); transform: translateX(0px);}
17% { opacity: 1; -webkit-transform: translateX(0px); transform: translateX(0px); }
20% { opacity: 0; -webkit-transform: translateX(00px); transform: translateX(0px); }
80% { opacity: 0; }
100% { opacity: 0; }
}
Here is a full demo:
.rw-words-1 span{
position: absolute;
opacity: 0;
overflow: hidden;
-webkit-animation: rotateWord 16s linear infinite 0s;
-ms-animation: rotateWord 16s linear infinite 0s;
animation: rotateWord 16s linear infinite 0s;
}
.rw-words-1 span:nth-child(2) {
-webkit-animation-delay: 4s;
-ms-animation-delay: 4s;
animation-delay: 4s;
}
.rw-words-1 span:nth-child(3) {
-webkit-animation-delay: 8s;
-ms-animation-delay: 8s;
animation-delay: 8s;
}
.rw-words-1 span:nth-child(4) {
-webkit-animation-delay: 12s;
-ms-animation-delay: 12s;
animation-delay: 12s;
}
#-webkit-keyframes rotateWord {
0% { opacity: 0; }
2% { opacity: 0; -webkit-transform: translateX(0px); }
5% { opacity: 1; -webkit-transform: translateX(0px);}
17% { opacity: 1; -webkit-transform: translateX(0px); }
20% { opacity: 0; -webkit-transform: translateX(0px); }
80% { opacity: 0; }
100% { opacity: 0; }
}
#-ms-keyframes rotateWord {
0% { opacity: 0; }
2% { opacity: 0; -ms-transform: translateX(0px); }
5% { opacity: 1; -ms-transform: translateX(0px);}
17% { opacity: 1; -ms-transform: translateX(0px); }
20% { opacity: 0; -ms-transform: translateX(0px); }
80% { opacity: 0; }
100% { opacity: 0; }
}
#keyframes rotateWord {
0% { opacity: 0; }
2% { opacity: 0; -webkit-transform: translateX(0px); transform: translateX(0px); }
5% { opacity: 1; -webkit-transform: translateX(0px); transform: translateX(0px);}
17% { opacity: 1; -webkit-transform: translateX(0px); transform: translateX(0px); }
20% { opacity: 0; -webkit-transform: translateX(00px); transform: translateX(0px); }
80% { opacity: 0; }
100% { opacity: 0; }
}
<div class="rw-words rw-words-1">
<span>Word 1</span>
<span>Word 2</span>
<span>Word 3</span>
<span>Word 4</span>
</div>
JSFiddle: https://jsfiddle.net/wx8r5kj7/
So my question is how to set the percentage of the #keyframes animation correctly.
If the animation is to complete in the first 25%, and you don't want the words to be fully transparant for too long, just reduce the periods during which the opacity is 0.
In your snippet, the opacity is at 0 from 0% to 2% and from 20% to 25%, or 1.12 seconds in total. I changed that to from 24% to 25% only, or about 0.16 second.
.rw-words-1 span{
position: absolute;
opacity: 0;
overflow: hidden;
-webkit-animation: rotateWord 16s linear infinite 0s;
-ms-animation: rotateWord 16s linear infinite 0s;
animation: rotateWord 16s linear infinite 0s;
}
.rw-words-1 span:nth-child(2) {
-webkit-animation-delay: 4s;
-ms-animation-delay: 4s;
animation-delay: 4s;
}
.rw-words-1 span:nth-child(3) {
-webkit-animation-delay: 8s;
-ms-animation-delay: 8s;
animation-delay: 8s;
}
.rw-words-1 span:nth-child(4) {
-webkit-animation-delay: 12s;
-ms-animation-delay: 12s;
animation-delay: 12s;
}
#-webkit-keyframes rotateWord {
0% { opacity: 0; -webkit-transform: translateX(0px); }
3% { opacity: 1; -webkit-transform: translateX(0px);}
21% { opacity: 1; -webkit-transform: translateX(0px); }
24% { opacity: 0; -webkit-transform: translateX(0px); }
80% { opacity: 0; }
100% { opacity: 0; }
}
#-ms-keyframes rotateWord {
0% { opacity: 0; -ms-transform: translateX(0px); }
3% { opacity: 1; -ms-transform: translateX(0px);}
21% { opacity: 1; -ms-transform: translateX(0px); }
24% { opacity: 0; -ms-transform: translateX(0px); }
80% { opacity: 0; }
100% { opacity: 0; }
}
#keyframes rotateWord {
0% { opacity: 0; -webkit-transform: translateX(0px); transform: translateX(0px); }
3% { opacity: 1; -webkit-transform: translateX(0px); transform: translateX(0px);}
21% { opacity: 1; -webkit-transform: translateX(0px); transform: translateX(0px); }
24% { opacity: 0; -webkit-transform: translateX(00px); transform: translateX(0px); }
80% { opacity: 0; }
100% { opacity: 0; }
}
<div class="rw-words rw-words-1">
<span>Word 1</span>
<span>Word 2</span>
<span>Word 3</span>
<span>Word 4</span>
</div>
Is this what you wanted?
Related
I am creating an animation that rotate text that's based on this website: https://tympanus.net/Tutorials/CSS3RotatingWords/
I would like to make the text stay longer and support unknow number of sentences:
<div style="height:25px;margin-bottom:5px;">
<div class="rw-words rw-words-1">
<span style="-webkit-animation-delay: 0s; -ms-animation-delay: 0s; animation-delay: 0s; ">This is sentence one</span>
<span style="-webkit-animation-delay: 6s; -ms-animation-delay: 6s; animation-delay: 6s; ">This is sentence two</span>
<span style="-webkit-animation-delay: 12s; -ms-animation-delay: 12s; animation-delay: 12s; ">This is sentence three</span>
</div>
</div>
<style>
.rw-words-1 span {
position: absolute;
opacity: 0;
overflow: hidden;
-webkit-animation: rotateWord 18s linear infinite 0s;
-ms-animation: rotateWord 18s linear infinite 0s;
animation: rotateWord 18s linear infinite 0s;
}
#-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: 1;
-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: 1;
-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;
}
}
</style>
Above codes work well but I would like the text to stay longer before rotating to the next. I've tried to change the keyframes % values but that only messes up the animation. What do I need to do to say keep each sentence up for 10 seconds before next? Thanks!
just wondering if there is a css only solution / trick to avoid the absolute element overlapping the content below.
I already learned that position absolute takes out the element from the layout so its not possible to give the parent element the height of its absolute child.
Maybe you guys know a workaround.
thanks for your time and thoughts
/*Sentence*/
.sentence{
color: #222;
font-size: 50px;
}
/*FadeIn*/
.fadeIn{
display: inline;
text-indent: 8px;
}
.fadeIn span{
animation: fadeEffect 12.5s linear infinite 0s;
-ms-animation: fadeEffect 12.5s linear infinite 0s;
-webkit-animation: fadeEffect 12.5s linear infinite 0s;
color: #00abe9;
opacity: 0;
overflow: hidden;
position: absolute;
}
.fadeIn span:nth-child(2){
animation-delay: 2.5s;
-ms-animation-delay: 2.5s;
-webkit-animation-delay: 2.5s;
}
.fadeIn span:nth-child(3){
animation-delay: 5s;
-ms-animation-delay: 5s;
-webkit-animation-delay: 5s;
}
.fadeIn span:nth-child(4){
animation-delay: 7.5s;
-ms-animation-delay: 7.5s;
-webkit-animation-delay: 7.5s;
}
.fadeIn span:nth-child(5){
animation-delay: 10s;
-ms-animation-delay: 10s;
-webkit-animation-delay: 10s;
}
/*FadeIn Animation*/
#-moz-keyframes fadeEffect{
0% { opacity: 0; }
5% { opacity: 0; -moz-transform: translateY(0px); }
10% { opacity: 1; -moz-transform: translateY(0px); }
25% { opacity: 1; -moz-transform: translateY(0px); }
30% { opacity: 0; -moz-transform: translateY(0px); }
80% { opacity: 0; }
100% { opacity: 0; }
}
#-webkit-keyframes fadeEffect{
0% { opacity: 0; }
5% { opacity: 0; -webkit-transform: translateY(0px); }
10% { opacity: 1; -webkit-transform: translateY(0px); }
25% { opacity: 1; -webkit-transform: translateY(0px); }
30% { opacity: 0; -webkit-transform: translateY(0px); }
80% { opacity: 0; }
100% { opacity: 0; }
}
#-ms-keyframes fadeEffect{
0% { opacity: 0; }
5% { opacity: 0; -ms-transform: translateY(0px); }
10% { opacity: 1; -ms-transform: translateY(0px); }
25% { opacity: 1; -ms-transform: translateY(0px); }
30% { opacity: 0; -ms-transform: translateY(0px); }
80% { opacity: 0; }
100% { opacity: 0; }
}
<body>
<h2 class="sentence">
<div class="fadeIn">
<span>Handsome.</span>
<span>Clean.</span>
<span>Elegant.</span>
<span>Magnificent.</span>
<span>Adorable.</span>
</div>
</h2>
<h2>LOrem iaoeg egaa eg aeg aeg aegoaegaokeg aeogk aeogkae gok </h2>
</body>
As soon as I add a letter it works. So maybe adding a pseudo element is a solution?
/*Sentence*/
.sentence{
color: #222;
font-size: 50px;
}
/*FadeIn*/
.fadeIn{
display: inline;
text-indent: 8px;
}
.fadeIn span{
animation: fadeEffect 12.5s linear infinite 0s;
-ms-animation: fadeEffect 12.5s linear infinite 0s;
-webkit-animation: fadeEffect 12.5s linear infinite 0s;
color: #00abe9;
opacity: 0;
overflow: hidden;
position: absolute;
}
.fadeIn span:nth-child(2){
animation-delay: 2.5s;
-ms-animation-delay: 2.5s;
-webkit-animation-delay: 2.5s;
}
.fadeIn span:nth-child(3){
animation-delay: 5s;
-ms-animation-delay: 5s;
-webkit-animation-delay: 5s;
}
.fadeIn span:nth-child(4){
animation-delay: 7.5s;
-ms-animation-delay: 7.5s;
-webkit-animation-delay: 7.5s;
}
.fadeIn span:nth-child(5){
animation-delay: 10s;
-ms-animation-delay: 10s;
-webkit-animation-delay: 10s;
}
/*FadeIn Animation*/
#-moz-keyframes fadeEffect{
0% { opacity: 0; }
5% { opacity: 0; -moz-transform: translateY(0px); }
10% { opacity: 1; -moz-transform: translateY(0px); }
25% { opacity: 1; -moz-transform: translateY(0px); }
30% { opacity: 0; -moz-transform: translateY(0px); }
80% { opacity: 0; }
100% { opacity: 0; }
}
#-webkit-keyframes fadeEffect{
0% { opacity: 0; }
5% { opacity: 0; -webkit-transform: translateY(0px); }
10% { opacity: 1; -webkit-transform: translateY(0px); }
25% { opacity: 1; -webkit-transform: translateY(0px); }
30% { opacity: 0; -webkit-transform: translateY(0px); }
80% { opacity: 0; }
100% { opacity: 0; }
}
#-ms-keyframes fadeEffect{
0% { opacity: 0; }
5% { opacity: 0; -ms-transform: translateY(0px); }
10% { opacity: 1; -ms-transform: translateY(0px); }
25% { opacity: 1; -ms-transform: translateY(0px); }
30% { opacity: 0; -ms-transform: translateY(0px); }
80% { opacity: 0; }
100% { opacity: 0; }
}
<body>
<h2 class="sentence">A
<div class="fadeIn">
<span>Handsome.</span>
<span>Clean.</span>
<span>Elegant.</span>
<span>Magnificent.</span>
<span>Adorable.</span>
</div>
</h2>
<h2>LOrem iaoeg egaa eg aeg aeg aegoaegaokeg aeogk aeogkae gok </h2>
</body>
The problem is, .fadeIn element now has no non-absolute children, so basically it has a height of 0 because absolute elements don't get calculated in the height of their parent.
Thus, the only thing you need to do is giving a proper height to .fadeIn element.
There are many ways you can handle that, but I made this one for you. I'm going to make :first-child of your spans inside of .fadeIn element as position: static ( default position value ) to let its parent know how much height should it take.
The other way is to set height: 50px ( for example ) for you .fadeIn element to let that element know how much should it take as height.
The other way ( as you already mentioned ) is to make another child ( in your example, an A ) to let it know the height value.
and many more ways.
But I've taken the first solution ( there were some other changes according to that context to make sure everything's working properly ). Look at the following code:
/*Sentence*/
.sentence{
color: #222;
font-size: 50px;
}
.fadeIn { position: relative; }
.fadeIn span{
animation: fadeEffect 12.5s linear infinite 0s;
-ms-animation: fadeEffect 12.5s linear infinite 0s;
-webkit-animation: fadeEffect 12.5s linear infinite 0s;
color: #00abe9;
opacity: 0;
top: 0;
overflow: hidden;
position: absolute;
}
.fadeIn span:first-child { position: static; display: block }
.fadeIn span:nth-child(2){
animation-delay: 2.5s;
-ms-animation-delay: 2.5s;
-webkit-animation-delay: 2.5s;
}
.fadeIn span:nth-child(3){
animation-delay: 5s;
-ms-animation-delay: 5s;
-webkit-animation-delay: 5s;
}
.fadeIn span:nth-child(4){
animation-delay: 7.5s;
-ms-animation-delay: 7.5s;
-webkit-animation-delay: 7.5s;
}
.fadeIn span:nth-child(5){
animation-delay: 10s;
-ms-animation-delay: 10s;
-webkit-animation-delay: 10s;
}
/*FadeIn Animation*/
#-moz-keyframes fadeEffect{
0% { opacity: 0; }
5% { opacity: 0; -moz-transform: translateY(0px); }
10% { opacity: 1; -moz-transform: translateY(0px); }
25% { opacity: 1; -moz-transform: translateY(0px); }
30% { opacity: 0; -moz-transform: translateY(0px); }
80% { opacity: 0; }
100% { opacity: 0; }
}
#-webkit-keyframes fadeEffect{
0% { opacity: 0; }
5% { opacity: 0; -webkit-transform: translateY(0px); }
10% { opacity: 1; -webkit-transform: translateY(0px); }
25% { opacity: 1; -webkit-transform: translateY(0px); }
30% { opacity: 0; -webkit-transform: translateY(0px); }
80% { opacity: 0; }
100% { opacity: 0; }
}
#-ms-keyframes fadeEffect{
0% { opacity: 0; }
5% { opacity: 0; -ms-transform: translateY(0px); }
10% { opacity: 1; -ms-transform: translateY(0px); }
25% { opacity: 1; -ms-transform: translateY(0px); }
30% { opacity: 0; -ms-transform: translateY(0px); }
80% { opacity: 0; }
100% { opacity: 0; }
}
<body>
<h2 class="sentence">
<div class="fadeIn">
<span>Handsome.</span>
<span>Clean.</span>
<span>Elegant.</span>
<span>Magnificent.</span>
<span>Adorable.</span>
</div>
</h2>
<h2>LOrem iaoeg egaa eg aeg aeg aegoaegaokeg aeogk aeogkae gok </h2>
</body>
Don't make all the elements to be absolute. Keep one relative (or static) so it allocate the needed space:
/*Sentence*/
.sentence {
color: #222;
font-size: 50px;
}
/*FadeIn*/
.fadeIn {
display: inline;
text-indent: 8px;
position: relative;/*added*/
}
.fadeIn span {
animation: fadeEffect 12.5s linear infinite 0s;
color: #00abe9;
opacity: 0;
overflow: hidden;
position: absolute;
left: 0; /*added*/
top: 0; /*added*/
}
/*added this*/
.fadeIn span:first-child {
position: relative;
}
/**/
.fadeIn span:nth-child(2) {
animation-delay: 2.5s;
}
.fadeIn span:nth-child(3) {
animation-delay: 5s;
}
.fadeIn span:nth-child(4) {
animation-delay: 7.5s;
}
.fadeIn span:nth-child(5) {
animation-delay: 10s;
}
/*FadeIn Animation*/
#keyframes fadeEffect {
0% {
opacity: 0;
}
5% {
opacity: 0;
transform: translateY(0px);
}
10% {
opacity: 1;
transform: translateY(0px);
}
25% {
opacity: 1;
transform: translateY(0px);
}
30% {
opacity: 0;
transform: translateY(0px);
}
80% {
opacity: 0;
}
100% {
opacity: 0;
}
}
<h2 class="sentence">
<div class="fadeIn">
<span>Handsome.</span>
<span>Clean.</span>
<span>Elegant.</span>
<span>Magnificent.</span>
<span>Adorable.</span>
</div>
</h2>
<h2>LOrem iaoeg egaa eg aeg aeg aegoaegaokeg aeogk aeogkae gok </h2>
I'm using a simple top-to-bottom vertical css text scroll animation and want it to stop on the last keyframe word (everyone). I've added the 'forwards' animation-fill-mode but nothing appears after it plays through once. Code: https://codepen.io/oconnellsail/pen/MZmgbo
/*Vertical Sliding*/
.slidingVertical{
display: inherit;
}
.slidingVertical span{
animation: topToBottom 7.5s linear 0s 1 forwards;
-ms-animation: topToBottom 7.5s linear 0s 1 forwards;
-webkit-animation: topToBottom 7.5s linear 0s 1 forwards;
color: #13b2cf;
opacity: 0;
overflow: hidden;
position: absolute;
}
.slidingVertical span:nth-child(2){
animation-delay: 2.5s;
-ms-animation-delay: 2.5s;
-webkit-animation-delay: 2.5s;
}
.slidingVertical span:nth-child(3){
animation-delay: 5s;
-ms-animation-delay: 5s;
-webkit-animation-delay: 5s;
}
/*topToBottom Animation*/
#-moz-keyframes topToBottom{
0% { opacity: 0; }
5% { opacity: 0; -moz-transform: translateY(-50px); }
10% { opacity: 1; -moz-transform: translateY(0px); }
25% { opacity: 1; -moz-transform: translateY(0px); }
30% { opacity: 0; -moz-transform: translateY(50px); }
80% { opacity: 0; }
100% { opacity: 0; }
}
#-webkit-keyframes topToBottom{
0% { opacity: 0; }
5% { opacity: 0; -webkit-transform: translateY(-50px); }
10% { opacity: 1; -webkit-transform: translateY(0px); }
25% { opacity: 1; -webkit-transform: translateY(0px); }
30% { opacity: 0; -webkit-transform: translateY(50px); }
80% { opacity: 0; }
100% { opacity: 0; }
}
#-ms-keyframes topToBottom{
0% { opacity: 0; }
5% { opacity: 0; -ms-transform: translateY(-50px); }
10% { opacity: 1; -ms-transform: translateY(0px); }
25% { opacity: 1; -ms-transform: translateY(0px); }
30% { opacity: 0; -ms-transform: translateY(50px); }
80% { opacity: 0; }
100% { opacity: 0; }
}
<h1 class="sentence">
<div class="slidingVertical">
<span>Your struggling student</span>
<span>Your child</span>
<span>Everyone</span>
</div>
<br>can be a math person.</h1>
You can add one more animation topToMiddle.
#-webkit-keyframes topToMiddle{
0% { opacity: 0; }
5% { opacity: 0; -webkit-transform: translateY(-50px); }
10% { opacity: 1; -webkit-transform: translateY(0px); }
100% { opacity: 1; }
}
and add it to .slidingVertical span:nth-child(3){.... .... animation-name: topToMiddle;}
/*Vertical Sliding*/
.slidingVertical{
display: inherit;
}
.slidingVertical span{
animation: topToBottom 7.5s linear 0s 1 forwards;
-ms-animation: topToBottom 7.5s linear 0s 1 forwards;
-webkit-animation: topToBottom 7.5s linear 0s 1 forwards;
color: #13b2cf;
opacity: 0;
overflow: hidden;
position: absolute;
}
.slidingVertical span:nth-child(2){
animation-delay: 2.5s;
-ms-animation-delay: 2.5s;
-webkit-animation-delay: 2.5s;
}
.slidingVertical span:nth-child(3){
animation-delay: 5s;
-ms-animation-delay: 5s;
-webkit-animation-delay: 5s;
animation-name: topToMiddle;
}
#-webkit-keyframes topToMiddle{
0% { opacity: 0; }
5% { opacity: 0; -webkit-transform: translateY(-50px); }
10% { opacity: 1; -webkit-transform: translateY(0px); }
100% { opacity: 1; }
}
/*topToBottom Animation*/
#-moz-keyframes topToBottom{
0% { opacity: 0; }
5% { opacity: 0; -moz-transform: translateY(-50px); }
10% { opacity: 1; -moz-transform: translateY(0px); }
25% { opacity: 1; -moz-transform: translateY(0px); }
30% { opacity: 0; -moz-transform: translateY(50px); }
80% { opacity: 0; }
100% { opacity: 0; }
}
#-webkit-keyframes topToBottom{
0% { opacity: 0; }
5% { opacity: 0; -webkit-transform: translateY(-50px); }
10% { opacity: 1; -webkit-transform: translateY(0px); }
25% { opacity: 1; -webkit-transform: translateY(0px); }
30% { opacity: 0; -webkit-transform: translateY(50px); }
80% { opacity: 0; }
100% { opacity: 0; }
}
#-ms-keyframes topToBottom{
0% { opacity: 0; }
5% { opacity: 0; -ms-transform: translateY(-50px); }
10% { opacity: 1; -ms-transform: translateY(0px); }
25% { opacity: 1; -ms-transform: translateY(0px); }
30% { opacity: 0; -ms-transform: translateY(50px); }
80% { opacity: 0; }
100% { opacity: 0; }
}
<h1 class="sentence">
<div class="slidingVertical">
<span>Your struggling student</span>
<span>Your child</span>
<span>Everyone</span>
</div>
<br>can be a math person.</h1>
Test it here
Maybe you need create a animation to last span like that: https://codepen.io/anon/pen/KbBpqM
and use:
animation-iteration-count: 1
I've been trying to implement this codepen: https://codepen.io/paulrogers/pen/KWORqz
Specifically this piece:
/*Horizontal Sliding*/
.slidingHorizontal{
display: inline;
text-indent: 8px;
}
.slidingHorizontal span{
animation: leftToRight 12.5s linear infinite 0s;
-ms-animation: leftToRight 12.5s linear infinite 0s;
-webkit-animation: leftToRight 12.5s linear infinite 0s;
color: #00abe9;
opacity: 0;
overflow: hidden;
position: absolute;
}
.slidingHorizontal span:nth-child(2){
animation-delay: 2.5s;
-ms-animation-delay: 2.5s;
-webkit-animation-delay: 2.5s;
}
.slidingHorizontal span:nth-child(3){
animation-delay: 5s;
-ms-animation-delay: 5s;
-webkit-animation-delay: 5s;
}
.slidingHorizontal span:nth-child(4){
animation-delay: 7.5s;
-ms-animation-delay: 7.5s;
-webkit-animation-delay: 7.5s;
}
.slidingHorizontal span:nth-child(5){
animation-delay: 10s;
-ms-animation-delay: 10s;
-webkit-animation-delay: 10s;
}
/*leftToRight Animation*/
#-moz-keyframes leftToRight{
0% { opacity: 0; }
5% { opacity: 0; -moz-transform: translateX(-50px); }
10% { opacity: 1; -moz-transform: translateX(0px); }
25% { opacity: 1; -moz-transform: translateX(0px); }
30% { opacity: 0; -moz-transform: translateX(50px); }
80% { opacity: 0; }
100% { opacity: 0; }
}
#-webkit-keyframes leftToRight{
0% { opacity: 0; }
5% { opacity: 0; -webkit-transform: translateX(-50px); }
10% { opacity: 1; -webkit-transform: translateX(0px); }
25% { opacity: 1; -webkit-transform: translateX(0px); }
30% { opacity: 0; -webkit-transform: translateX(50px); }
80% { opacity: 0; }
100% { opacity: 0; }
}
#-ms-keyframes leftToRight{
0% { opacity: 0; }
5% { opacity: 0; -ms-transform: translateX(-50px); }
10% { opacity: 1; -ms-transform: translateX(0px); }
25% { opacity: 1; -ms-transform: translateX(0px); }
30% { opacity: 0; -ms-transform: translateX(50px); }
80% { opacity: 0; }
100% { opacity: 0; }
}
I'm trying to integrate the css into my main.scss file -- I'm aware that the scss file doesn't recognize keyframes -- but I'm having trouble converting.
Any help would be appreciated! I'm very new to scss so any extra explanations would be awesome!
Ok so I am pretty new to css3 animations and I am trying to get to grips with it. So what I am trying to do is animate two images one to slide from the bottom and the other to slide in from the right and then repeat this. I have the images sliding in ok but what I cant get to work is repeating the 1st animation after the last has ended.
Below is the css that I have at the min:
.image-1{
-webkit-animation-iteration-count : infinite;
float:right;
animation-name: slideUp, hide;
-webkit-animation-name: slideUp, hide;
-moz-animation-name: slideUp, hide;
animation-duration: 1s, 6s;
-webkit-animation-duration: 1s, 6s;
-moz-animation-duration: 1s, 6s;
animation-timing-function: ease;
-webkit-animation-timing-function: ease;
-moz-animation-timing-function: ease;
opacity: 0;
}
.image-2{
float:right;
animation-name: slideLeft, hide;
-webkit-animation-name: slideLeft, hide;
animation-duration: 1s, 6s;
-webkit-animation-duration: 1s, 6s;
-moz-animation-duration: 1s, 6s;
animation-timing-function: ease-in-out;
-webkit-animation-timing-function: ease-in-out;
animation-delay:6s, 6s;
-moz-animation-delay:6s, 6s;
-webkit-animation-delay:6s, 6s;
-o-animation-delay:6s, 6s;
opacity: 0;
}
#keyframes hide
{
from { opacity: 1; } to { opacity: 1 }
}
#-moz-keyframes hide
{
from { opacity: 1; } to { opacity: 1 }
}
#-webkit-keyframes hide
{
from { opacity: 1; } to { opacity: 1 }
}
#-o-keyframes hide
{
from { opacity: 1; } to { opacity: 1 }
}
/*
==============================================
slideUp
==============================================
*/
#keyframes slideUp {
0% {
transform: translateY(100%);
opacity: 0.0;
}
50%{
transform: translateY(-2%);
opacity: 1;
}
65%{
transform: translateY(4%);
opacity: 1;
}
80%{
transform: translateY(-1%);
opacity: 1;
}
95%{
transform: translateY(2%);
opacity: 1;
}
100% {
transform: translateY(0%);
opacity: 1;
}
}
#-webkit-keyframes slideUp {
0% {
-webkit-transform: translateY(100%);
opacity: 0.0;
}
50%{
-webkit-transform: translateY(-3%);
opacity: 1;
}
65%{
-webkit-transform: translateY(5%);
opacity: 1;
}
80%{
-webkit-transform: translateY(-1%);
opacity: 1;
}
95%{
-webkit-transform: translateY(2%);
opacity: 1;
}
100% {
-webkit-transform: translateY(0%);
opacity: 1;
}
}
/*
==============================================
slideLeft
==============================================
*/
#keyframes slideLeft {
0% {
transform: translateX(150%);
}
50%{
transform: translateX(-8%);
}
65%{
transform: translateX(4%);
}
80%{
transform: translateX(-4%);
}
95%{
transform: translateX(2%);
}
100% {
transform: translateX(0%);
}
}
#-webkit-keyframes slideLeft {
0% {
-webkit-transform: translateX(150%);
}
50%{
-webkit-transform: translateX(-8%);
}
65%{
-webkit-transform: translateX(4%);
}
80%{
-webkit-transform: translateX(-4%);
}
95%{
-webkit-transform: translateX(2%);
}
100% {
-webkit-transform: translateX(0%);
}
}
You can start a repeating animation with a delay (this delay should be the time your first animation takes) by using
animation-delay:2s;
and you repeat by using
animation-iteration-count:infinite;
You can find a nice example with all css3 animation properties here:
http://www.w3schools.com/css/tryit.asp?filename=trycss3_animation4