Pen Settings

HTML

CSS

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

JavaScript

Babel includes JSX processing.

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

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

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.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
 
  
  <section class="section-1">
    <p class="scroll-down"></p>scroll down!
  </section>

  <section class="section-2">
    <div class="wrapper">
      <p class=" test-paragraph" id="Test-Paragraph"> Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
      </p>

      <p class=" test-paragraph" id="Test-Paragraph"> Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
      </p>

  </section>
</body>

</html>
              
            
!

CSS

              
                * {
  box-sizing: border-box;
}

body {
  
  height: 5000px;
  
}

.section-1 {
  height:100vh;
  font-family: Neue Montreal;
  color: #141414;
  line-height: 1.25;
  font-size: 2vw;
  text-transform:uppercase;
  letter-spacing: .25px;
}

section-2 {
  height: 100vh;
}

.wrapper {
  width: 65vw;
  margin-top: 22vw;
  margin-left: auto;
  margin-right: auto;
}

.test-paragraph {
  font-family: neue montreal;
  color: #141414;
  line-height: 1.25;
  font-size: 2vw;
  text-transform:uppercase;
}

span.test-paragraph {
  display: inline-block;
}

#Test-Paragraph > div {
  overflow: hidden;
}




              
            
!

JS

              
                (function ($) {
  /**
   * Creates a temporary clone
   *
   * @param element element The element to clone
   */
  function _createTemp(element) {
    return element.clone().css({ position: "absolute" });
  }

  /**
   * Splits contents into words, keeping their original Html tag. Note that this
   * tags *each* word with the tag it was found in, so when the wrapping begins
   * the tags stay intact. This may have an effect on your styles (say, if you have
   * margin, each word will inherit those styles).
   *
   * @param node contents The contents
   */
  function _splitHtmlWords(contents) {
    var words = [];
    var splitContent;
    for (var c = 0; c < contents.length; c++) {
      if (contents[c].nodeName === "BR") {
        words.push("<br>");
        continue;
      }
      if (contents[c].nodeType == 3) {
        splitContent = _splitWords(
          contents[c].textContent || contents[c].toString()
        );
      } else {
        var tag = $(contents[c]).clone();
        splitContent = _splitHtmlWords(tag.contents());
        for (var t = 0; t < splitContent.length; t++) {
          tag.empty();
          splitContent[t] = tag
            .html(splitContent[t])
            .wrap("<p></p>")
            .parent()
            .html();
        }
      }
      for (var w = 0; w < splitContent.length; w++) {
        if (splitContent[w] === "") {
          continue;
        }
        words.push(splitContent[w]);
      }
    }
    return words;
  }

  /**
   * Splits words by spaces
   *
   * @param string text The text to split
   */
  function _splitWords(text) {
    return text.split(/\s+/);
  }

  /**
   * Formats html with tags and wrappers.
   *
   * @param tag
   * @param html content wrapped by the tag
   * @param index Current line index
   */
  function _markupContent(tag, html, index) {
    // wrap in a temp div so .html() gives us the tags we specify
    tag = '<div class="stop">' + tag;
    // find the deepest child, add html, then find the parent
    var $outer = $(tag)
      .find('*:not(:has("*"))')
      .html(html)
      .closest(".stop")
      .slice(-1);

    // jQuery does not support setting CSS vars until 3.2, so manually set them
    $outer.children().each(function (i, element) {
      element.style.setProperty("--line-index", index);
    });

    return $outer.html();
  }

  /**
   * The jQuery plugin function. See the top of this file for information on the
   * options
   */
  $.fn.splitLines = function (options) {
    var settings = {
      width: "auto",
      tag: "<div>",
      wrap: "",
      keepHtml: true
    };
    if (options) {
      $.extend(settings, options);
    }
    var newHtml = _createTemp(this);
    var contents = this.contents();
    var text = this.text();
    this.append(newHtml);
    newHtml.text("42");
    var maxHeight = newHtml.height() + 2;
    newHtml.empty();

    var tempLine = _createTemp(newHtml);
    var width = settings.width;
    if (settings.width === "auto") {
      width = this[0].offsetWidth;
    }
    tempLine.width(width);
    this.append(tempLine);
    var words = settings.keepHtml
      ? _splitHtmlWords(contents)
      : _splitWords(text);
    var prev;
    var lineCount = 0;
    for (var w = 0; w < words.length; w++) {
      var html = tempLine.html();
      tempLine.html(html + words[w] + " ");
      if (tempLine.html() == prev) {
        // repeating word, it will never fit so just use it instead of failing
        prev = "";
        newHtml.append(
          _markupContent(settings.tag, tempLine.html(), lineCount)
        );
        tempLine.html("");
        continue;
      }
      if (tempLine.height() > maxHeight) {
        prev = tempLine.html();
        tempLine.html(html);
        newHtml.append(
          _markupContent(settings.tag, tempLine.html(), lineCount)
        );
        tempLine.html("");
        w--;
        lineCount++;
      }
    }
    newHtml.append(_markupContent(settings.tag, tempLine.html(), lineCount));

    this.html(newHtml.html());
  };
})(jQuery);

$("p.test-paragraph").each(function () {
  $(this).splitLines({
    tag: '<div><span class="test-paragraph">',
    keepHtml: true
  });
});

const tl = gsap.timeline({
  defaults: {
    stagger: { each: .065 },
    ease: "custom.create(.165, .84, .44, 1)",
    yPercent: 100,
    duration: .85
  },
  scrollTrigger: {
    trigger: ".wrapper",
    start: "center center",
    markers: true
  }
});

tl.from("span.test-paragraph", {
  
})




              
            
!
999px

Console