I want to achieve the next animation
So I decided to split every single letter into an element.
Then I displayed every as a inline-block element to translate vertically them as in the example.
PROBLEM: When I displayed every span as a inline-block, the word spacing is not showing. How can I solve this?
Also, having more than one text to animate, I have some doubts about how to code the progressive delay on JS.
Thanks in advance
$('.splitSpan').each(function (index) {
var characters = $(this).text().split("");
$this = $(this);
$this.empty();
$.each(characters, function (i, el) {
$this.append('<span class="letter-' + i + '">' + el + '</span>');
});
});
.splitSpan span{
display:inline-block;
}
@keyframes down {
from {transform:translateY(4px);}
to {transform:translateY(0px);}
}
@keyframes up {
from {transform:translateY(-4px);}
to {transform:translateY(0px);}
}
.splitSpan span:nth-child(even){
animation-name: down;
animation-duration: 1s;
}
.splitSpan span:nth-child(odd){
animation-name: up;
animation-duration: 1s;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<p class="splitSpan">HELLO WORLD<p>
<p class="splitSpan">SECOND SENTENCE</p>
2
Answers
You can add
for space in your codeWorking example:
As Reyno commented, add
white-space-collapse: preserve
You could use
animation-delay
to delay the animation of the second sentence