css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation


Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

              <!-- This effect is an enhanced version of https://codepen.io/GreenSock/pen/AGzci which only animated 1 word at a time.  -->

<link href='https://fonts.googleapis.com/css?family=Asap:400,700' rel='stylesheet' type='text/css'>
<div id="demo"></div>
<h2>special features</h2>
  <li>Duration of each chunk's animation is based on character count giving you more time to read longer chunks</li>    
  <li>Last part of the sentence stays on screen longer</li>
  <li>Pause added after each sentence</li>


#demo h3 {
  font-family: 'Asap', sans-serif;
h2 {
li {
  font-family: 'Asap', sans-serif;
              var container = $("#demo"),
    _sentenceEndExp = /(\.|\?|!)$/g; //regular expression to sense punctuation that indicates the end of a sentence so that we can adjust timing accordingly

//this function just takes a string of text and splits it into an array based on the maximum length that should be allowed to exist in each line, and when it encounters the end of a sentence (ending in ".", "?", or "!"), it will force a line break too.
function buildChunks(text, maxLength) {
  if (maxLength === undefined) {
    return text.split(" ");
  var words = text.split(" "),
      wordCount = words.length,
      chunk = [],
      chunks = [], i;
  for (i = 0; i < wordCount; i++){
    if (_sentenceEndExp.test(words[i]) || i === wordCount - 1 || chunk.join(" ").length + words[i+1].length > maxLength) {
      chunks.push(chunk.join(" "));
      chunk = [];
  return chunks;

function machineGun(chunks, maxLength) {
  //in case "chunks" isn't an array, we'll build chunks automatically
  if (!(chunks instanceof Array)) {
    chunks = buildChunks(chunks, maxLength);
  var tl = new TimelineMax({delay:0.6, repeat:2, repeatDelay:4}),
      time = 0,
      chunk, element, duration, isSentenceEnd, i;
  for (i = 0; i < chunks.length; i++) {
    chunk = chunks[i];
    isSentenceEnd = _sentenceEndExp.test(chunk) || (i === chunks.length - 1);
    element = $("<h3>" + chunk + "</h3>").appendTo(container);
      duration = Math.max(0.5, chunk.length * 0.08); //longer words take longer to read, so adjust timing. Minimum of 0.5 seconds.
      if (isSentenceEnd) {
        duration += 0.6; //if it's the last word in a sentence, drag out the timing a bit for a dramatic pause.
      //set opacity and scale to 0 initially. We set z to 0.01 just to kick in 3D rendering in the browser which makes things render a bit more smoothly.
    TweenLite.set(element, {autoAlpha:0, scale:0, z:0.01});
    //the SlowMo ease is like an easeOutIn but it's configurable in terms of strength and how long the slope is linear. See https://www.greensock.com/v12/#slowmo and https://api.greensock.com/js/com/greensock/easing/SlowMo.html
    tl.to(element, duration, {scale:1.2,  ease:SlowMo.ease.config(0.25, 0.9)}, time)
      //notice the 3rd parameter of the SlowMo config is true in the following tween - that causes it to yoyo, meaning opacity (autoAlpha) will go up to 1 during the tween, and then back down to 0 at the end. 
		 	  .to(element, duration, {autoAlpha:1, ease:SlowMo.ease.config(0.25, 0.9, true)}, time);
      time += duration - 0.05;
      if (isSentenceEnd) {
        time += 0.6; //at the end of a sentence, add a pause for dramatic effect.

machineGun("This text will suck you in and you will not believe what is coming next. Actually that is about all that is going to happen. I am glad you watched. THE END", 12);

/* learn more about the GreenSock Animation Platfrom (GSAP) for JS


watch a quick video on how TimelineLite allows you to sequence animations like a pro


🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................