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

              
                <!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>BOO!</title>
	<link href="https://fonts.googleapis.com/css?family=Montserrat:800,900" rel="stylesheet">
	<!--  https://elrumordelaluz.github.io/csshake/	 -->
	<link rel="stylesheet" type="text/css" href="https://csshake.surge.sh/csshake.min.css">
</head>

<body>
<!-- 	<audio id="audio" src="https://cldup.com/E6_tXFKBxB.mp3"></audio> -->
	<audio id="audio" src="https://cldup.com/6hJxu-FuLf.mp3"></audio>
	<a href="javascript:play();" style="display: flex; height: 99.8vh;">
		<div class="wrap">
			<h1 id="main-head">Click anywhere to get a spooky surprise!</h1>
			<div class="headline">
				<h2 class="spooky">Boo!</h2>
			</div>
			<div class="ghost-wrap">
				<div id="boo" class="ghosty spook">
					<?xml version="1.0" encoding="utf-8"?>
					<svg version="1.1" id="ghost" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 129.5 215.3" style="enable-background:new 0 0 129.5 215.3;" xml:space="preserve">
						<style type="text/css">

						</style>
						<!-- BODY -->
							<path id="body" class="body" d="M64.7,1.5C29.7,1.6,1.5,30.2,1.5,65.2v133.9c0,8.2,6.6,14.8,14.8,14.8l0,0c8.2,0,14.8-6.6,14.8-14.8 v-18.6c0-2.2,1.7-4,3.8-4.2l0,0c2.5-0.2,4.6,1.7,4.6,4.2v8.7c0,5.6,4.5,10.1,10.1,10.1l0,0c5.6,0,10.1-4.5,10.1-10.1v-11.7 c0-2,1.5-3.6,3.5-3.8l0,0c2.2-0.2,4.2,1.6,4.2,3.8v0.4c0,6.8,5.5,12.3,12.3,12.3l0,0c6.8,0,12.3-5.5,12.3-12.3v-3.8 c0-1.7,1.3-3,2.9-3.2l0,0c1.9-0.2,3.5,1.3,3.5,3.2v17.7c0,8.2,6.6,14.8,14.8,14.8l0,0c8.2,0,14.8-6.6,14.8-14.8V64.9 C128.2,29.8,99.7,1.4,64.7,1.5z"/>
						<!-- LEFT EYE -->
							<path id="left_eye" class="eye" d="M44.2,82.8L44.2,82.8c-4.4,0-8-3.6-8-8v-7.3c0-4.4,3.6-8,8-8l0,0c4.4,0,8,3.6,8,8v7.3 C52.3,79.2,48.7,82.8,44.2,82.8z"/>
							<path id="left_eye_gloss" class="eye_gloss" d="M47.6,72.9L47.6,72.9c-2,0-3.7-1.6-3.7-3.7v-1.6c0-2,1.6-3.7,3.7-3.7l0,0 c2,0,3.7,1.6,3.7,3.7v1.6C51.2,71.3,49.6,72.9,47.6,72.9z"/>
						<!-- RIGHT EYE -->
							<path id="right_eye" class="eye" d="M85.5,82.8L85.5,82.8c-4.4,0-8-3.6-8-8v-7.3c0-4.4,3.6-8,8-8l0,0c4.4,0,8,3.6,8,8v7.3 C93.5,79.2,89.9,82.8,85.5,82.8z"/>
							<path id="right_eye_gloss" class="eye_gloss" d="M88.8,72.9L88.8,72.9c-2,0-3.7-1.6-3.7-3.7v-1.6c0-2,1.6-3.7,3.7-3.7l0,0 c2,0,3.7,1.6,3.7,3.7v1.6C92.5,71.3,90.8,72.9,88.8,72.9z"/>
						<!-- MOUTH -->
							<path id="mouth" class="stroke" d="M34.2,115.1c0,0,28.3-10.1,59.3-8.8"/>
							<path id="dimple_right" class="stroke" d="M91.8,101.3c0,0,3.6,3,4.4,9.3"/>
							<path id="dimple_left" class="stroke" d="M36.6,110.4c0,0-3.6,3-4.4,9.3"/>
							<path id="tongue" class="tongue" d="M67,107.6V118c0,5.7,4.7,10.4,10.4,10.4l0,0c5.7,0,10.4-4.7,10.4-10.4v-11.8 C80.5,106.1,73.4,106.7,67,107.6z"/>
							<line id="tongue_interior" class="stroke" x1="77.4" y1="107.7" x2="77.4" y2="117.3"/>
						<!-- BODY GLOSS -->
							<line id="gloss_06" class="stroke" x1="8.9" y1="179.9" x2="8.9" y2="187.4"/>
							<line id="gloss_05" class="stroke" x1="8.9" y1="158.1" x2="8.9" y2="173"/>
							<line id="gloss_04" class="stroke" x1="8.9" y1="112.5" x2="8.9" y2="146.9"/>
							<path id="gloss_03" class="stroke" d="M68.1,10.1C67,10,65.8,10,64.7,10c-3.5,0-6.9,0.3-10.2,1"/>
							<path id="gloss_02" class="stroke" d="M120.8,70.2v-4.4c0-26.7-18.8-49.1-43.9-54.6"/>
							<line id="gloss_01" class="stroke" x1="121.1" y1="106.1" x2="121.1" y2="82.2"/>
					</svg>
				</div>
			</div>	
		</div>
	</a>
</body>
</html>
              
            
!

CSS

              
                /* *************************
 * VARIABLES
************************* */
	// COLORS
	$white:  		#ffffff;
	$black:  		#000000;
	$pink:   		#ff0046;
	$purple: 		#45103e;
	$purple_light: #d3b8d1;

	// FONTS
	$sans:	'Montserrat', 'Helvetica', Arial, sans-serif;
	$bold:	800;

	// LAYOUT
	@mixin flexin {
		display:    flex;
		flex-wrap:  wrap;
		flex-basis: 100%;
	}

	@mixin flex-cent-cent {
		align-items:     center;
		justify-content: center;
	}

	@mixin flex-cent-top {
		justify-content: center;
		align-content:   flex-start;
	}

	$rel: relative;
	$abs: absolute;
	$fix: fixed;

/* *************************
 * GENERIC STYLES
************************* */
	body {
		height: 100vh;
		/* Permalink - use to edit and share this gradient: http://colorzilla.com/gradient-editor/#ff0046+0,45103e+100 */
		background: $pink; /* Old browsers */
		background: -moz-linear-gradient(-45deg, $pink 0%, $purple 100%); /* FF3.6-15 */
		background: -webkit-linear-gradient(-45deg, $pink 0%,$purple 100%); /* Chrome10-25,Safari5.1-6 */
		background: linear-gradient(135deg, $pink 0%,$purple 100%); /* W3C, IE10+, FF16+, Chrome26+, Opera12+, Safari7+ */
		filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='$pink', endColorstr='$purple',GradientType=1 );
		/* IE6-9 fallback on horizontal gradient */
		background-repeat: no-repeat;
		padding: 0;
		margin: 0;
		font-family: $sans;
		text-transform: uppercase;
		overflow: hidden;
		a {
			display: flex;
			height: 99.8vh;
			text-decoration: none;
			color: rgba( $white, 0.6 );
		}
	}

/* *************************
 * INTERIOR WRAP STYLES
************************* */
	.wrap {
		padding: 0;
		margin: 0;
		@include flexin;
		@include flex-cent-top;
		position: $rel;
		h1, h2 {
			width: 100%;
			text-align: center;
			color: rgba( $white, 0.9 );
			font-family: $sans;
			text-transform: uppercase;
			font-weight: $bold;
			font-size: 18px;
			text-shadow: 0 2px 10px rgba( $black, 0.8 );
			position: $rel;
			z-index: 3;
			@media (min-width: 800px) {
				font-size: 36px;
			}
		}
		.headline {
			width: 100%;
			text-align: center;
			height: auto;
			display: flex;
			justify-content: center;
			align-items: center;
			h2 {
				color: rgba( $white, 0.6 );
				width: auto;
				font-size: 76px;
				margin: 0;
				text-shadow: 0 1px 0 rgba( $white, 0.3 ),
							 0 2px 0 rgba( $white, 0.3 ),
							 0 3px 0 rgba( $white, 0.3 ),
							 0 4px 0 rgba( $white, 0.3 ),
							 0 5px 0 rgba( $white, 0.3 ),
							 0 6px 1px rgba( $black, 0.1 ),
							 0 0 5px rgba( $black, 0.1 ),
							 0 1px 3px rgba( $black, 0.3 ),
							 0 3px 5px rgba( $black, 0.2 ),
							 0 5px 10px rgba( $black, 0.25 ),
							 0 10px 10px rgba( $black, 0.2 ),
							 0 20px 20px rgba( $black, 0.15 );
				@media (min-width: 1200px) {
					font-size: 86px;
				}
			}
		}
		.ghost-wrap {
			@include flexin;
			@include flex-cent-cent;
			position: $rel;
			height: calc(100vh - 289px);
			.ghosty {
				min-width: 80px;
				max-width: 80px;
				position: $fix;
				z-index: 2;
				@media (min-width: 950px) {
					min-width: 100px;
					max-width: 100px;
				}
			}
		}
	}

/* *************************
 * SVG STYLES
************************* */
	.ghosty {
		.body{
			fill: $white;
			stroke: $purple;
			stroke-width: 2.8511;
			stroke-linecap: round;
			stroke-linejoin: round;
			stroke-miterlimit: 10;
		}
		.eye{
			fill: $purple;
		}
		.eye_gloss{
			fill: #D3B8D1;


		}
		.stroke{
			fill: none;
			stroke: $purple;
			stroke-width: 2.851;
			stroke-linecap: round;
			stroke-linejoin: round;
			stroke-miterlimit: 10;
		}
		.tongue{
			fill: #D3B8D1;
			stroke: $purple;
			stroke-width: 2.8511;
			stroke-linecap: round;
			stroke-linejoin: round;
			stroke-miterlimit: 10;
		}
	}


/* *************************
 * MISC STYLES
************************* */
	.opacity {
		opacity: 0;
		transition: all 0.5s ease-out;
	}

              
            
!

JS

              
                var body = $('body');
var ghost = $('.ghosty');
var gwrap = $('.ghost-wrap');
var head = $('.headline');

$(document).ready(function() {
	animateGhost();
});

function makeNewPosition(){

	// Get viewport dimensions (remove the dimension of the div)
	var h = $(window).height() - ghost.height();
	var w = $(window).width() - ghost.width();
	
	var nh = Math.floor(Math.random() * (h - 50));
	var nw = Math.floor(Math.random() * (w - 50));

	return [nh,nw];

}

function animateGhost(){

	var newPos = makeNewPosition();	
	var oldPos = ghost.offset();
	
	var speed = calcSpeed([oldPos.top, oldPos.left], newPos);
	
	ghost.animate({
			top: newPos[0],
			left: newPos[1]
		},
		speed,
		function(){
			animateGhost();
		}
	);

};

function calcSpeed(prev, next) {

	var x = Math.abs(prev[1] - next[1]);
	var y = Math.abs(prev[0] - next[0]);

	var greatest = x > y ? x : y;

	var speedModifier = 0.085;

	var speed = Math.ceil(greatest/speedModifier);

	return speed;

}

function play(){
	
	var audio = document.getElementById('audio');
	var head = document.getElementById('main-head');
	var spooky = document.getElementsByClassName('spooky');
	var spook = document.getElementsByClassName('spook');
	
	
	audio.play();
	audio.onplay = function() {
		$(spooky).addClass('shake-constant shake-opacity');
		$(head).addClass('opacity');
	};
	audio.onended = function() {
		$(spooky).removeClass('shake-constant shake-opacity');
		// $(head).removeClass('opacity');
	};
	
}



              
            
!
999px

Console