Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs 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 its URL and the proper URL extension.

+ 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

              
                
              
            
!

CSS

              
                html, body {
	margin: 0;
	background: #222;
	font: 16px/1.21 'Helvetica Neue',helvetica,verdana,sans-serif;
	-webkit-font-smoothing: antialiased;
	-moz-osx-font-smoothing: grayscale;
	overflow: hidden;
	touch-action: none;
}

.input {
	margin: 5px 10px;
	touch-action: normal;
	p {
		margin: 0;
		padding: 0 0 5px;
		color: #666;
	}
	
	textarea {
		box-sizing: border-box;
		width: 100%;
		height: 6.5em;
		background: #333;
		border: 1px solid #555;
		color: #CCC;
		font-size: 100%;
		outline: none;
	}
}

.logo {
	position: absolute;
	left: 50%;
	top: 50%;
	transform: translate(-50%,-50%);
	overflow: visible;
	
	.line {
		overflow: visible;
		will-change: width;
		pointer-events: none;
		
		.animated & {
			transition: all 100ms ease;
		}

		> span {
			display: block;
			position: absolute;
			width: 40px;
			height: 40px;
			line-height: 40px;
			font-size: 30px;
			text-align: center;
			color: #FFF;
			text-shadow: 0 0 2px #000;
			opacity: 0.6;
			overflow: hidden;
			text-transform: uppercase;
			backface-visibility: hidden;
			transform: translate3d(0px,0px,0);
			will-change: transform;
			cursor: default;
			pointer-events: none;
			
			.animated & {
				transition: all 100ms ease;
			}
		}
	}
}
              
            
!

JS

              
                /** @jsx h */
let { Component, render, h } = preact;
let { bind, memoize } = decko;
let { pow, sqrt, sin, cos, tan, atan2 } = Math;

const TOUCH = navigator.maxTouchPoints>1;

// preact.options.debounceRendering = requestAnimationFrame;

/** Root component, handles top-level state, mouse tracking, and running a demo */
class Main extends Component {
	state = { text:'', lines:[] };

	// hook up touch/mouse follower and run the gross demo
	componentDidMount() {
		addEventListener('resize', this.updatePosition);
		// addEventListener(TOUCH?'touchmove':'mousemove', this.handleMouseMove);
		const evt = 'onpointermove' in document.body ? 'pointermove' : 'mousemove';
		// TOUCH?'touchmove':'mousemove'
		addEventListener(evt, this.handleMouseMove);
		this.runHorribleDemo();
	}
	
	componentDidUpdate() {
		let { text } = this.state;
		if (text!==this.lastText) {
			this.lastText = text;
			this.updatePosition();
		}
	}
	
	updatePosition = () => {
		this.position = this.base.querySelector('.logo').getBoundingClientRect();
	}

	handleMouseMove = (e) => {
		if (this.timer) clearTimeout(this.timer), this.timer = null;
		let t = e.touches && e.touches[0] || e;
		this.setState({
			x: t.pageX - this.position.left,
			y: t.pageY - this.position.top
		});
		return e.preventDefault(), false;
	}

	// seriously ignore this, it's demo flash
	runHorribleDemo() {
		this.setState({ animated:true });

		let i = 0;
		this.timer = setInterval( () => {
			let { width, height } = this.position;
			this.setState({
				x: width/2 + cos(++i/8)*width/2,
				y: height/2 + sin(i/8)*height/2
			});
		}, 10);

		let wait = (t, c) => setTimeout(c, t);
		let animate = (text, c, i=0) => {
			let timer = setInterval( () => {
				if (i++===text.length) clearTimeout(timer), c();
				else this.setState({ text: text.substring(0, i) });
			}, 30);
		};
		sequence([
			[animate, '••••••\nPREACT\n••••••'],
			[wait, 500],
			[animate, 'jason\nmiller'],
			[wait, 500],
			[animate, 'codepen:\ndevelopit\n\ngithub:\ndevelopit\n\ntwitter:\n_developit'],
			[wait, 500],
			[animate, '••••••\n•type•\n•some•\n•text•\n••••••'],
			[wait, 500]
		], () => {
			clearTimeout(this.timer);
			this.setState({ x:-200, y:-200, animated:false });
		});
	}

	// get a random color for each new index
	color = memoize((index) => {
		let rnd = () => Math.random()*255|0;
		return `rgb(${rnd()},${rnd()},${rnd()})`;
	})

	// update the text, breaking it into lines and setting them as state
	textToLines = memoize((text) => {
		text = (text || '').trim();
		return text.split('\n').map( (text, i) => ({
			text, color: this.color(i)
		}));
	});

	render({}, { over, x, y, text, animated }) {
		let lines = this.textToLines(text);
		return (
			<div class={{ animated }}>
				<div class="input">
					<p><strong>Hint:</strong> You can change the text while moving your mouse.</p>
					<textarea onInput={ this.linkState('text') }>{ text }</textarea>
				</div>
				<div class="logo">{
					lines.map( ({ text, color }, index) => (
						<Line {...{ index, text, x, y, color }} />
					))
				}</div>
			</div>
		);
	}
}


/** Represents a line, which is a sequence of characters */
const Line = ({ x=0, y=0, index, text, color:background }) => {
	let letters = text.split('').map( (letter, i) => {
		let left = i * 40,
			top = index * 40,
			xc = left+20,
			yc = top+20;

		// calculate vector from mouse to centroid
		let mag = sqrt( pow(x-xc,2) + pow(y-yc,2) ),
			dir = atan2(y-yc, x-xc),
			offset = mag < 200 ? (mag/10 - 20) : 0;

		let transform = `translate3d(${cos(dir)*offset}px, ${sin(dir)*offset}px, 0)`;
		return <span style={{ background, transform, left, top }}>{ letter }</span>;
	});
	return (
		<div class="line" style={{
			width: letters.length*40,
			height: 40,
		}}>{ letters }</div>
	);
};

setTimeout( () => {
	render(<Main />, document.body);
});





// https://git.io/praline
function sequence(funcs, callback) {
	let i = 0;
	let c = funcs.length;
	if (!c) return callback(null);
	let results = [];
	let next = () => {
		let func = funcs[i++];
		let args = [];
		if (Array.isArray(func)) {
			args = func.slice();
			func = args.shift();
		}
		args.push( (err, data) => {
			if (err) return callback(err);
			results[i-1] = data;
			if (i<c) next();
			else callback(null, ...results);
		});
		func(...args);
	};
	next();
}
              
            
!
999px

Console