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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ 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 class="message">Why GSAP, WHY?!</div>
<button>Start</button>
              
            
!

CSS

              
                body, html { height: 100%; }
body { 
	display: flex; flex-direction: column; justify-content: center; align-items: center; 
	font: 36px/1.5 "Verdana", Sans-Serif;
	color: fuchsia;
}
              
            
!

JS

              
                
// Problem with multiple text-write-sequences

$(document).ready(function() {
	var tl = new TimelineMax();
		tl
			.add(write(".message", "this is blank now :("))
			.to(".message", 1, { color: "red" })
			.add(write(".message", "But <span>...</span> [pause=.4] another message kills it all!"))
			.to(".message", 1, { color: "green" })
			.reverse()
		;
	
	$("button").click(function() {
		tl.play(0);
	})
})


write = function(elem, text, cps ) {

	// jQuerynize- 
	var $elem = $(elem);
	
	// if text is empty, write the current text 
	var text = (text == undefined || text == "") ? $elem.text() : text; 
	
	var originalHTML = $elem.html();
	
	var $container = $elem.clone();
	$elem.html("");
	$container.appendTo($elem);

	// set chars per second 
	cps = (cps != undefined) ? cps : 22;

	// change the HTML of $elem to the text and immediately create a SplitText 
	var split = new SplitText( $container.html( text ), { type: "words, chars" } );

	var tl = new TimelineMax({onStart:function() {
		$container.appendTo($elem.html(""));
	}, onReverseComplete: function() {
		$elem.html(originalHTML);
	}});
	var offset = .1; // start at .1, in order to have at least one frame with not letters at all

	// Helper function  
	// in case I will add some randomeness 
	var offsetUp = function() { return offset = offset + 1/cps; } // random is nich kuhl  + ((chanceRoll(20)) ? 1/cps*random(0,2) : 0) 

	// Damit beim initical call auch eine Animation passiert 
	TweenMax.set(split.chars, { opacity: 0 });

	// Pause regexp, example:   [pause=.5] or [pause=12]
	var pause = new RegExp(/\[pause=([^\]]+)\]/);

	$.each(split.words, function(index, word) {

		// if pause regexp has a match, increase offset with captured value
		// and delete delete word and skip this one loop
		var match = pause.exec($(word).text());
		if (match != null) {
			offset = offset + parseFloat(match[1]);
			$(word).remove();
			return true; // jquery way to skip one $.each; // return false would break it totally
		}

		// no whitespace at the first word
		// first word index 0, therefore effecitvely false, profit! 
		if (index) { offsetUp(); } // offset einen buchstaben weiter

		$.each(word.children, function(index, char) {

			tl.set(char, { opacity: 1 }, offset);

			offsetUp();
			// slow spans down for dramatical effect 
			if ($(word).parent("span").length > 0) { offsetUp(); offsetUp(); offsetUp(); } // I know I could use a factor as parameter! :D

		})
	});
	
	$elem.html(originalHTML);

	return tl;
}
              
            
!
999px

Console