Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Whether you do it with CSS or JavaScript, you (or some library) are going to have to put each letter in its own element in order to animate them individually. E.g.:</p> <pre><code>&lt;p&gt;Hi there&lt;/p&gt; </code></pre> <p>...will need to become</p> <pre><code>&lt;p&gt;&lt;span&gt;H&lt;/span&gt;&lt;span&gt;i&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;t&lt;/span&gt;&lt;span&gt;h&lt;/span&gt;&lt;span&gt;e&lt;/span&gt;&lt;span&gt;r&lt;/span&gt;&lt;span&gt;e&lt;/span&gt;&lt;/p&gt; </code></pre> <p>That leads me to think a JavaScript solution might be preferred, as otherwise your markup will be a bit...unpleasant to write.</p> <p>With JavaScript using jQuery, it's quite easy to replace the text of an element with a bunch of spans containing that text character-by-character:</p> <pre><code>var target = $("#target"); target.html(target.text().replace(/./g, "&lt;span&gt;$&amp;&lt;/span&gt;")); </code></pre> <p>Then you animate the <code>span</code>s. (Note I'm assuming here that the element in question contains <strong>only</strong> text, not text and child elements. It's more complex if you have child elements.)</p> <p>Here's a very basic example:</p> <p>HTML:</p> <pre><code>&lt;p id="target" style="margin-top: 20px"&gt;Hi there&lt;/p&gt; </code></pre> <p>JavaScript:</p> <pre><code>jQuery(function($) { var target = $("#target"); target.html(target.text().replace(/./g, "&lt;span&gt;$&amp;&lt;/span&gt;")); setTimeout(runAnimation, 250); function runAnimation() { var index, spans; index = 0; spans = target.children(); doOne(); function doOne() { var span = $(spans[index]); if (!$.trim(span.text())) { // Skip blanks next(); return; } // Do this one span.css({ position: "relative", }).animate({ top: "-20" }, "fast").animate({ top: "0" }, "fast", function() { span.css("position", ""); next(); }); } function next() { ++index; if (index &lt; spans.length) { doOne(); } else { setTimeout(runAnimation, 500); } } } }); </code></pre> <p><a href="http://jsbin.com/ifoyay">Live copy</a> | <a href="http://jsbin.com/ifoyay/edit">source</a></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload