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.

            
              <div class="container">
	<div class="mooncake">
		<div class="antennas">
			<div class="antenna"></div>
			<div class="antenna"></div>
		</div>
		<div class="face">
			<div class="eye"></div>
			<div class="mouth"></div>
			<div class="eye"></div>
		</div>
		<div class="feet">
			<div class="foot"></div>
			<div class="foot"></div>
		</div>
	</div>
</div>
<div class="rays"></div>
<div class="radial"></div>
            
          
!
            
              * {
  &, &:before, &:after {
    box-sizing: border-box;
  }
}
html {
  font-family: 'Open Sans', sans-serif;
  font-size: 16px;
}

body {
  margin: 0;
	background-color: #333;
	background-image: radial-gradient(circle, #fcfcfc 0%, #b8cdde 30%, #283b75 100%);
	overflow: hidden;
	position: fixed;
	width: 100%;
}

$color-main: #a7ff7c;
$color-shadow: #86dc76;
$color-highlight: #fefefe;

// $color-main: #C55;
// $color-shadow: darken($color-main, 15%);
// $color-highlight: lighten($color-main, 15%);

.container {
	display: flex;
	justify-content: center;
	align-items: center;
	height: 100vh;
}

.mooncake {
	display: flex;
	justify-content: center;
	align-items: center;
	flex-direction: column;
	width: 200px;
	height: 160px;
	position: relative;
	background-color: $color-main;
	border-radius: 100%;
	border: 2px solid #000;
	perspective: 400;
	transform-style: preserve-3d;
	transform: translateZ(20px);
	transition: width .2s ease, height .2s ease;
	-webkit-tap-highlight-color: transparent; 
	z-index: 9;
	will-change: transform;
	user-select: none;
	background-image: 
				radial-gradient(circle at 69% 10%, $color-highlight 0, $color-highlight 6px, $color-main 6px, $color-main 10%, transparent 10%, transparent 100%),
		radial-gradient(ellipse, transparent 66%, $color-main 66% , $color-main 100%),

		radial-gradient(circle at 52% 84%, transparent 0, transparent 73%, $color-highlight 73%, $color-highlight 80%, transparent 80%),
		radial-gradient(circle at 50% 10%, transparent 0, transparent 73%, $color-shadow 73%, $color-shadow 80%, transparent 80%);

	
	.face {
		display: flex;
		width: 100%;
		padding: 0 10px;
		justify-content: space-around;
		align-items: flex-end;
	}
	.eye {
		height: 40px;
		width: 40px;
		background-color: #fff;
		border-radius: 100%;
		border: 2px solid black;
		display: flex;
		justify-content: center;
		align-items: center;
		transition: all .2s;
		will-change: transform;
		&:after {
			content: '';
			display: block;
			background-color: #000;
			height: 4px;
			width: 4px;
			border-radius: 100%;	
			transition: all .4s ease-in-out;
			transition-delay: .3s;
			height: 20px;
			width: 20px;
			transform: scale(0.2);			
			will-change: transform;
			background-image:
			 radial-gradient(circle at 70% 45%, #fff 0, #fff 2px, #000 2px, #000 2px, transparent 5px, transparent 100%),
				radial-gradient(circle at 40% 35%, #fff 0, #fff 3px, #000 3px, #000 3px, transparent 3px, transparent 100%);
		}
	}
	.mouth {
		display: block;
		height: 5px;
		width: 20px;
		border-radius: 0 0 40px 40px/0 0 20px 20px;
		border-bottom: 2px solid black;
		transition: all 5s ease-in-out;
		transition-delay: .2s;
	}
	.feet {
		position: absolute;
		display: flex;
		justify-content: space-between;
		width: 80%;
		bottom: -15px;
		z-index: -10;
		transform: translateZ(-10px);

	}
	.foot {
		background-color: $color-main;
		height: 60px;
		width: 50px;
		border-radius: 90% / 75%;
		border: 2px solid #000;
		will-change: transform;
		background-image: 
		radial-gradient(circle, transparent 66%, $color-main 66% , $color-main 100%),
		radial-gradient(circle at 70% 10%, transparent 0, transparent 73%, $color-shadow 73%, $color-shadow 80%, transparent 80%);
		position: relative;
		overflow: hidden;
		transform: rotate(10deg);
		transition: all .1s ease-in;
		
		&:before {
			content: '';
			display: block;
			height: 50px;
			width: 200%;
			border-radius: 100%;
			background-color: #000;
			position: absolute;
			left: 10px;
			top: -8px;
			
		}
		& + .foot {
			transform: rotate(-10deg);
		}
		& + .foot:before {
			left: auto;
			right: 10px;
		}
	}
	.antennas {
		position: absolute;
		display: flex;
		justify-content: space-between;
		width: 50%;
		top: -30px;
		z-index: -10;
		transform: translateZ(-10px);
	}
	.antenna {
		width: 3px;
    height: 45px;
    // border: 2px solid black;
    background-color: $color-main;
		filter: drop-shadow( -1px 1px 0 black)  drop-shadow( -1px -1px 0 black) drop-shadow(1px 1px 0 black)  drop-shadow( 1px -1px 0 black) drop-shadow( 0px -1px 0 black);
		position: relative;
		transition: all .1s ease-in-out;
		transform-origin: bottom center;
    transform: rotateZ(-30deg);
		will-change: transform;
		& + .antenna {
			transform:rotateZ(30deg);
		}
		&:after {
			content: '';
			display: block;
			width: 10px;
			height: 10px;
			border-radius: 100%;
			background-color: $color-main;
			position: absolute;
			top: -10px;
			left: -5px;
		}
	}
	
	&--hovered {
		.eye {
			&:after {
				transition-duration: 2s;
				transition-delay: .1s;
				transform: scale(1);
			}
		}
		.mouth {
			transition-duration: 1.5s;
			transition-delay: .3s;
			border-radius: 0 0 40px 40px/0 0 20px 20px;
		}
	}
		
	 
	&--grabbed {
		height: 150px;
		width: 190px;
		.antenna {
			transform: rotateZ(-15deg);
			& + .antenna {
				transform: rotateZ(15deg);
			}
		}
		.eye {
			&:after {
				transition-duration: 0.1s;
				transition-delay: 0s;
				transform: scale(0.2);
			}
		}
		.mouth {
			transition-duration: 0.1s;
			transition-delay: 0s;
			border-radius: 0 0 0 0/0 0 0 0;
		}
		.foot {
			transform: rotate(-10deg);
			& + .foot {
				transform: rotate(10deg);
			}
		}
  }
}

@keyframes rotating {
  from {
    transform: scale(2) translateZ(0) rotate(0deg);
  }
  to {
    transform: scale(2) translateZ(0) rotate(360deg);
  }
}
.rays {
	$rayColor1: white;
	$rayColor2: black;
	
	$c1-1: $rayColor1;
	$c1-2: $rayColor1;
	$c1-3: $rayColor1;
	
	opacity: 0.05;
	
	
	transform: scale(2) translateZ(0) rotate(0deg);
	position: absolute;
	top: 0;
	left: 0;
	right: 0;
	bottom: 0;
	
	animation: rotating 120s linear infinite;


	$c2-1: $rayColor2;
	$c2-2: $rayColor2;
	$c2-3: $rayColor2;
	&:before, &:after {
		content: '';
		display: block;
		height: 100%;
		width: 100%;
		position: absolute;
		z-index: 1;
		top: 0;
		left: 0;
		opacity: 1;
		transform: translateZ(0);
		background-image:
		linear-gradient(170deg, transparent 50%, $c1-1 50%, $c1-2 60%, $c1-3 60%),		
		linear-gradient(160deg, transparent 50%, $c2-1 50%, $c2-2 70%, $c2-3 70%),		
		linear-gradient(150deg, transparent 50%, $c1-1 50%, $c1-2 60%, $c1-3 60%),		
		linear-gradient(140deg, transparent 50%, $c2-1 50%, $c2-2 70%, $c2-3 70%),		
		linear-gradient(130deg, transparent 50%, $c1-1 50%, $c1-2 60%, $c1-3 60%),		
		linear-gradient(120deg, transparent 50%, $c2-1 50%, $c2-2 70%, $c2-3 70%),		
		linear-gradient(110deg, transparent 50%, $c1-1 50%, $c1-2 60%, $c1-3 60%),		
		linear-gradient(100deg, transparent 50%, $c2-1 50%, $c2-2 70%, $c2-3 70%),		
		linear-gradient(90deg, transparent 50%, $c1-1 50%, $c1-2 60%, $c1-3 60%),		
		linear-gradient(80deg, transparent 50%, $c2-1 50%, $c2-2 70%, $c2-3 70%),		
		linear-gradient(70deg, transparent 50%, $c1-1 50%, $c1-2 60%, $c1-3 60%),		
		linear-gradient(60deg, transparent 50%, $c2-1 50%, $c2-2 70%, $c2-3 70%),		
		linear-gradient(50deg, transparent 50%, $c1-1 50%, $c1-2 60%, $c1-3 60%),		
		linear-gradient(40deg, transparent 50%, $c2-1 50%, $c2-2 70%, $c2-3 70%),
		linear-gradient(30deg, transparent 50%, $c1-1 50%, $c1-2 60%, $c1-3 60%),		
		linear-gradient(20deg, transparent 50%, $c2-1 50%, $c2-2 70%, $c2-3 70%),
		linear-gradient(10deg, transparent 50%, $c1-1 50%, $c1-2 60%, $c1-3 60%),		
		linear-gradient(0deg, transparent 50%, $c2-1 50%, $c2-2 70%, $c2-3 70%),
		linear-gradient(-10deg, transparent 50%, $c1-1 50%, $c1-2 60%, $c1-3 60%);
	
		
	 	clip-path: polygon(0% 0%, 100% 0%, 100% 50%, 0% 50% ); 
	}
	&:after {
		transform: rotate(180deg);
	}
}

.radial {
		background-image: radial-gradient(circle, #fcfcfc 0%, #b8cdde 30%, #283b75 100%);
		height: 100%;
		width: 100%;
		position: absolute;
		z-index: 2;
		top: 0;
		left: 0;
		mix-blend-mode: hard-light;
}

.cursor {
	&--grab {
		cursor: grab;
	}
	&--grabbing {
		cursor: grabbing;
	}
}
            
          
!
            
              const chookityHmm =
	"https://www.jeffreyvanderheide.nl/Chookity/WooHoo%20Chookity%20Dookity.wav";
const chookitySqueek =
	"https://www.jeffreyvanderheide.nl/Chookity/Chookity%202.wav";
const chookityAnnoyed =
	"https://www.jeffreyvanderheide.nl/Chookity/Chookity%203.wav";
const chookityScream =
	"https://www.jeffreyvanderheide.nl/Chookity/Chookity%204.wav";
const chookity0 = new Audio(chookityHmm);
const chookity1 = new Audio(chookitySqueek);
const chookity2 = new Audio(chookityAnnoyed);
const chookity3 = new Audio(chookityScream);

const target = document.querySelector(".mooncake");

const floating = TweenMax.fromTo(
	target,
	2,
	{ y: "-25%" },
	{ y: "25%", repeat: -1, yoyo: true, force3D: true, ease: Sine.easeInOut }
);

class DragBounce {
	constructor(element) {
		this.element = element;
		this.mouseDown = false;
		this.startPosition = { x: 0, y: 0 };
		this.previousEvent = null;
		this.previousPosition = { x: 0, y: 0 };
		this.setupEventHandlers();
		this.tween = null;
		this.touchStartFlag = false;
		this.shouldHmm = true;
	}

	setupEventHandlers() {
		this.element.classList.add("cursor--grab");
		this.element.addEventListener("mousedown", e => {
			this.preventDoubleFire(() => {
				this.startHandler(e);
			});
		});
		this.element.addEventListener("touchstart", e => {
			this.preventDoubleFire(() => {
				this.startHandler(e);
			});
		});
		this.element.addEventListener("mouseenter", e => {
			this.element.classList.add("mooncake--hovered");
			// // const chookity = new Audio(chookityHmm);
			setTimeout(()=> {
				if (this.shouldHmm) {
					chookity0.play();
				}
			}, 1000);
		});
		this.element.addEventListener("mouseleave", e => {
			this.element.classList.remove("mooncake--hovered");
		});
		document.addEventListener("mousemove", e => {
			this.moveHandler(e);
		});
		document.addEventListener("touchmove", e => {
			this.moveHandler(e);
		});
		document.addEventListener("mouseup", e => {
			this.stopHandler(e);
		});
		document.addEventListener("touchend", e => {
			this.stopHandler(e);
		});
	}

	preventDoubleFire(cb) {
		if (!this.touchStartFlag) {
			this.touchStartFlag = true;
			setTimeout(() => {
				this.touchStartFlag = false;
			}, 100);
			cb();
		}
	}

	normalizeEvents(e) {
		if (e.touches && e.touches.length > 0) {
			return e.touches[0];
		}
		return e;
	}

	calculateDelta(e) {
		const previousEvent = this.previousEvent;
		let deltaX = 0;
		let deltaY = 0;
		if (previousEvent) {
			deltaX = e.screenX - previousEvent.screenX;
			deltaY = e.screenY - previousEvent.screenY;
		}
		this.previousEvent = e;
		return {
			x: deltaX,
			y: deltaY
		};
	}

	startHandler(e) {
		this.mouseDown = true;
		this.element.classList.add("cursor--grabbing");
		this.element.classList.add("mooncake--grabbed");
		const chookity = new Audio(chookitySqueek);
		chookity.play();
		this.shouldHmm = false;
		floating.pause();
	}

	moveHandler(e) {
		if (this.mouseDown) {
			const _e = this.normalizeEvents(e);
			const d = this.calculateDelta(_e);	
			this.updateElementPosition(d.x, d.y);
		}
	}

	stopHandler(e) {
		this.mouseDown = false;
		const distance = Math.sqrt(
			Math.pow(this.previousPosition.x - this.startPosition.x, 2) +
				Math.pow(this.previousPosition.y - this.startPosition.y, 2)
		);
		this.previousPosition = { x: 0, y: 0 };
		this.previousEvent = null;
		this.element.classList.remove("cursor--grabbing");
		this.element.classList.remove("mooncake--hovered");
		this.element.classList.remove("mooncake--grabbed");
		let chookitySound;
		if (distance > 300) {
			chookitySound = chookityAnnoyed;
		}
		if (distance > 500) {
			chookitySound = chookityScream;
		}
		const chookity = new Audio(chookitySound);
		chookity.play();
		TweenMax.to(this.element, 1, {
			x: this.startPosition.x,
			y: this.startPosition.y,
			force3D: true,
			ease: Elastic.easeOut.config(1, 0.3),
			onComplete: () => {
				floating.play();
				this.shouldHmm = true;
			}
		});
	}

	updateElementPosition(x, y) {
		const p = this.previousPosition;
		let newX = p.x + x;
		let newY = p.y + y;
		TweenMax.set(this.element, { x: `+=${x}px`, y: `+=${y}px`, force3D: true });
		this.previousPosition = { x: newX, y: newY };
	}
}

new DragBounce(target);

            
          
!
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