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 is required to process package imports. If you need a different preprocessor remove all packages first.

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

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

              
                <div class="overlay"></div>
<div class="title">
  <h1>GSAP SplitText Utility</h1>
</div>
  <div class="container alice-text">
  The Hatter opened his eyes very wide on hearing this; but all he said was, &ldquo;Why is a raven like a writing-desk?&rdquo; <br><br>
  &ldquo;Come, we shall have some fun now!&rdquo; thought Alice. &ldquo;I’m glad they’ve begun asking riddles. &mdash; I believe I can guess that,&rdquo; she added aloud.
</div> 



              
            
!

CSS

              
                $main-color: rgba(221, 146, 221, .8);
* {
  box-sizing: border-box;
}

html {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100vh;
  background: url(https://s3-us-west-2.amazonaws.com/s.cdpn.io/234228/aliceinwonderland.jpg) top center no-repeat;
  background-size: cover;
}

body{
  font-family:sans-serif;
  text-align: center;
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100vh;
  position: relative;
  overflow: hidden;
}

.overlay {
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  right: 0;
  margin: 0;
  padding: 0;
  background-color: darken($main-color, 40);
  z-index: 1;
}

.title {
  margin: 0;
  margin-bottom: 1em;
  padding: 0;
  position: relative;
  z-index: 2;
  h1 {
    margin: 0;
    padding: 0.5em;
    color: white;
    font-size: 2rem;
    font-weight: 300;
  }
}

.container {
	transform: translate3d(0, 0, 0);
  position: relative;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  height: auto;
  max-width: 600px;
  min-width: 300px;
  margin: 0 auto;
  padding: 1em;
  color: white;
  font-family: 'Playfair Display', serif;
  font-size: 1.5rem;
  line-height: 1.5;
  border-radius: 15px;
  z-index: 2;
  visibility:hidden;
  
  @media (min-width: 650px) {
    margin-top: 1em;  
  }
}

              
            
!

JS

              
                // vars
const aliceText = document.querySelector('.alice-text'),
      textTypes = new SplitText(aliceText, {
        type: 'lines, words' //split into lines and words
      }),
      linesLength = textTypes.lines.length,
      wordsLength = textTypes.words.length,
      button = document.querySelector('.btn'),
      tl = new TimelineMax();

// Prep the quote div for 3D 
TweenMax.set(aliceText, {transformPerspective:600, perspective:300, transformStyle:'preserve-3d', autoAlpha:1});

// rotate each line using random values
for(let i = 0; i < linesLength; i++) {
  tl.add('sentenceEntrance')
    .from(textTypes.lines[i], 1, {
    z: randomNumber(-100, 50),
    rotation: randomNumber(-360, 360),
    rotationX: randomNumber(-360, 360),
    rotationY: 90,
    opacity: 0,
    transformOrigin: '50% 75% 200',
    ease: Circ.easeInOut
  }, Math.random()*1.5);
}

// Rotate each word using some random values
for(let i = 0; i < wordsLength; i++) {
  tl.add('vanish')
    .to(textTypes.words[i], 0.5, {
    opacity: 0,
    z: randomNumber(-100, 500),
    rotation: randomNumber(360, 720),
    rotationX: randomNumber(-360, 360),
    rotationY: randomNumber(-360, 360)
  }, 'sentenceEntrance-=' + Math.random() * 0.2);
}

// Set each word to the original position (no rotation)
for(let i = 0; i < wordsLength; i++) {
  tl.add('end')
    .to(textTypes.words[i], 0.5, {
    opacity: 1,
    z: 0,
    x: 0,
    y: 0,
    rotation: 0,
    rotationX: 0,
    rotationY: 0,
    onComplete: function() {
      // This removes all the extra markup that SplitText 
      // adds to the DOM thereby cleaning up after the 
      // animation is done
      textTypes.revert(); 
    }
  }, 'vanish-=' + Math.random() * 0.2);
}

// Helper function you can find on GSAP demos 
// to randomize values, which I used above
function randomNumber(min, max){
	return Math.floor(Math.random() * (1 + max - min) + min);
}

              
            
!
999px

Console