css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv

Pen Settings

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

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <link href='https://fonts.googleapis.com/css?family=Share+Tech+Mono' rel='stylesheet' type='text/css'>
<h1 class="destroy">I am the very model of a modern Major-General,
I've information vegetable, animal, and mineral,
I know the kings of England, and I quote the fights historical
From Marathon to Waterloo, in order categorical<h1>
	
	<div class="funcSelect">
		<form>
			<input id="radio1" type="radio" name="function" value="crazy">Crazy<br>
<input id="radio2" type="radio" name="function" value="flyAway">Fly Away<br>
<input id="radio3" type="radio" name="function" value="crazy">Wave<br>
		</form>
	</div>
            
          
!
            
              body {
	height: 5000px;
}

.destroy {
	font-family: 'Share Tech Mono';
	font-size: 26px;
	position: fixed;
	display: block;
	text-align: center;
	top:100px;
	left: 50%;
	transform: translateX(-50%);
}

.destroy span {
	display: inline;
}

.funcSelect {
	background: #345D71;
	color: #fff;
	font-family: sans-serif;
	font-weight: 300;
	font-size: 16px;
	position: fixed;
	right: 0;
	padding: 30px;
	top:100px;
}

.funcSelect input {
	margin: 0 10px 15px 0
}

.funcSelect input:last-of-type{margin-bottom:0;}
            
          
!
            
              // Split the H1 to wrap every letter into a span

var splitLetters = $('.destroy').text().split('');
$('.destroy').empty();
$.each(splitLetters, function(i, v) {
	$('.destroy').append($('<span>').text(v));
});

// Set the point for the text to come together

var cleanPoint = 2000;

// Set each letter to display:inline-block and get their width so spaces don't collapse

$('.destroy span').each(function() {
	var letterWidth = $(this).width();
	$(this).css('display', 'inline-block');
	$(this).css('width', letterWidth);
});

// Set Go Crazy Function

function goCrazy() {
	$(window).scroll(function() {
		$('.destroy span').each(function() {
			var winX = $(window).height();
			var winY = $(window).width();
			var winTop = $(window).scrollTop();
			var cleanWinDif = Math.pow(Math.abs(winTop - cleanPoint) * 0.01, 4);
			var x = (Math.floor(Math.random() * cleanWinDif) - cleanWinDif / 2);
			var y = (Math.floor(Math.random() * cleanWinDif) - cleanWinDif / 2);
			$(this).css({
				'transform': 'translate(' + x + 'px,' + y + 'px)',
				'opacity': 1 - (cleanWinDif / 500)
			});
		});
	});
}

// Start Fly Away Function
function flyAway() {

	var flyX = [];
	var flyY = [];
	var winTop = $(window).scrollTop();
	var cleanWinDif = Math.pow(Math.abs(winTop - cleanPoint) * 0.01, 2);
	$('.destroy span').each(function() {
		var randX = (Math.random() * cleanWinDif) - cleanWinDif / 2;
		var randY = (Math.random() * cleanWinDif) - cleanWinDif / 2;
		flyX.push(randX);
		flyY.push(randY);
	});

	$(window).scroll(function() {

		$('.destroy span').each(function(index) {
			var winX = $(window).height();
			var winY = $(window).width();
			var winTop = $(window).scrollTop();
			var dirtyWinDif = winTop - cleanPoint;
			var cleanWinDif = Math.pow(Math.abs(winTop - cleanPoint) * 0.01, 5);
			var x = (flyX[index]) * (Math.pow((dirtyWinDif / 100) * 0.1, 5));
			var y = (flyY[index]) * (Math.pow((dirtyWinDif / 100) * 0.1, 5));
			$(this).css({
				'transform': 'translate(' + x + 'px,' + y + 'px)',
				'opacity': 1 - (cleanWinDif / 100000)
			});
		});
	});
}

// Initialize and set Function Select Box

$(window).click(function() {
	if ($('#radio1').prop('checked')) {
		goCrazy();
	} else if ($('#radio2').prop('checked')) {
		flyAway();
	} else {

	}

});
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console