<p contenteditable>Look at me, I have content, blah blah blah, lorem ipsum, pretty long text, maybe I'll wrap a few lines</p>
<button id="run">Run</button>
CSS
p {
font-size: 3em;
}
@keyframes rotate {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}
.l {
animation: rotate;
animation-duration: 1s;
}
JavaScript
function markup(el) {
let {top, left, width, height} = el.getBoundingClientRect();
let ctop = top, cleft = left;
el.style.width = width + "px";
el.style.height = height + "px";
window.getComputedStyle(el);
el.style.padding = 0;
let text = el.innerText;
let words = text.split(" ");
el.innerHTML = words.map(w => w.split("").map(l => `<span class="l">${l}</span>`).join("")).join(" ");
el.style.position = "relative";
let letters = el.querySelectorAll(".l");
for (let letter of letters) {
let {top, left} = letter.getBoundingClientRect();
letter.style.left = (left - cleft) + "px";
letter.style.top = (top - ctop) + "px";
//letter.style.position = "absolute";
window.setTimeout(function() {this.style.position = "absolute";}.bind(letter), 0)
}
}
run.addEventListener("click", function() {markup(document.querySelector("p"))});
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.