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

              
                <div id="textWrapper">
  <div id="text">This is my typed 
<br>text with GSAP :)</div>
    <span id="cursor">|</span>
</div>
              
            
!

CSS

              
                #textWrapper {
  width: 650px;
  margin: 20px;
  font-family: Arial, sans-serif;
  font-size: 40px;
  visibility: hidden;
  position: relative;
}

#text {
  position: absolute;
  color:#666;
  /*top:0;
  left:0;*/
}

#text > div:nth-child(7) {
  color:#237F0F; /* makes 7th word green */
}

#cursor {
  position: absolute;
  /*top:-3px;*/
  color: #111111;
  display: block;
  width:6px; /* controls thickness */
  overflow:hidden;
  /*font-family: Times, "Times New Roman", Georgia, serif;*/
}

.chars {
  visibility: hidden;
}
              
            
!

JS

              
                var $cursor = $("#cursor"),
    cursorInterval = 0.1,
    mySplitText = new SplitText("#text", {
       type: "words,chars",
       charsClass: "chars",
       position: "absolute"
    }),
    $chars = $(".chars"),
    tl = new TimelineMax({
      paused:true,
      delay: 1,      
      // comment out yoyo, repeat, repeatDelay, and onRepeat below if no reverse is needed
      yoyo: true,
      repeat: -1,
      repeatDelay: 2,
      onRepeat: function() {
           //stops blinking
           TweenLite.set($cursor, {
              autoAlpha: 1
          });
       }
  });

TweenLite.set("#textWrapper", {
  visibility: "visible"
});

//enable the blinking cursor
function blinkingCursor() {
  TweenMax.fromTo($cursor, 0.5, {
    autoAlpha: 0
  }, {
    autoAlpha: 1,
    repeat: -1,
    ease: SteppedEase.config(1)
  })
}

// this makes the cursor resume blinking after reversing
tl.call(blinkingCursor);

// this makes it visible (not blinking) when playing forward
tl.set($cursor, {autoAlpha: 1}, 0.1); 

//loop through all the chars and make them visible AND set cursor to their right at same time
$chars.each(function(i, el) {
  
  var $char = $(el),
      offset = $char.offset(),
      width = $char.width(),
      leftExtra = 30,
      topExtra = 23;
  
  // set initial $cursor CSS properties
  // you may have to play with leftExtra and topExtra for alignment
  tl.set($cursor, {
    left: (offset.left + width) - leftExtra,
    top:  (offset.top - topExtra)
  }, (i + 1) * cursorInterval);
  
  // set initial $char CSS properties
  tl.set($char, {
    autoAlpha: 1
  }, ((i + 1) * cursorInterval));
});

// re-call blinkingCursor function after the last char is displayed
tl.call(blinkingCursor);

// control speed of typing
tl.timeScale(0.6);

// start blinkingCursor before playing timeline
blinkingCursor();

// play timleine after 1 second delay
TweenMax.delayedCall(1, function(){
  tl.progress(1).progress(0);
  tl.play();
});
              
            
!
999px

Console