JSFiddle - React, Tailwind, and code Playground
by pradeep
HTML
<div id="someText">
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat.
</div>
CSS
#someText {
width: 200px;
//visibility: hidden;
}
.text-layer {
display: block;
overflow: hidden;
position: relative;
}
.text-layer span {
display: block;
overflow: hidden;
position: relative;
-webkit-transform: translate3d(0,82px,0);
transform: translate3d(0,82px,0);
transition: -webkit-transform .8s cubic-bezier(.215,.61,.355,1);
transition: transform .8s cubic-bezier(.215,.61,.355,1);
transition: transform .8s cubic-bezier(.215,.61,.355,1),-webkit-transform .8s cubic-bezier(.215,.61,.355,1);
transition-delay: 0.5s;
}
.active .text-layer span {
-webkit-transform: translate3d(0,0px,0);
transform: translate3d(0,0px,0);
}
JavaScript
var spanInserted = $('#someText').html().split(" ").join(" </span><span class='childspan'>");
var wrapped = ("<span class='childspan'>").concat(spanInserted, "</span>");
$('#someText').html(wrapped);
var refPos = $('#someText span.childspan:first-child').position().top;
var newPos;
$('#someText span.childspan').each(function(index) {
newPos = $(this).position().top
if (index == 0){
return;
}
if (newPos == refPos){
$(this).prepend($(this).prev().text() + " ");
$(this).prev().remove();
}
refPos = newPos;
});
$('#someText span.childspan').each(function(){
$(this).wrap('<span class="text-layer"></span>');
});
setTimeout(function(){
$("#someText").addClass("active");
},1000)