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="media">
		<div class="media__item">
			<svg id="dockOfBay" data-scene xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 648 469.6">
				<defs>
					<clipPath id="clip-path">
						<path class="cls-1" d="M274.33,141.67a90,90,0,1,0,90,90A90,90,0,0,0,274.33,141.67Zm0,98.63a8.63,8.63,0,1,1,8.63-8.62A8.63,8.63,0,0,1,274.33,240.29Z"/>
					</clipPath>
					<image id="dock-of-bay-cover" width="700" height="700" xlink:href="https://public-619e3.firebaseapp.com/dock-of-the-bay/dock-of-bay_med.jpg"/>
					<radialGradient id="grooves">
						<stop offset="45%" stop-color="#3176d4"/>
						<stop offset="45.5%" stop-color="#2f70cc"/>
						<stop offset="46%" stop-color="#3176d4"/>
						<stop offset="50%" stop-color="#3176d4"/>
						<stop offset="50.5%" stop-color="#2f70cc"/>
						<stop offset="51%" stop-color="#3176d4"/>
						<stop offset="60%" stop-color="#3176d4"/>
						<stop offset="60.5%" stop-color="#2f70cc"/>
						<stop offset="61%" stop-color="#3176d4"/>
						<stop offset="65%" stop-color="#3176d4"/>
						<stop offset="65.5%" stop-color="#2f70cc"/>
						<stop offset="66%" stop-color="#3176d4"/>
						<stop offset="75%" stop-color="#3176d4"/>
						<stop offset="75.5%" stop-color="#2f70cc"/>
						<stop offset="76%" stop-color="#3176d4"/>
						<stop offset="79%" stop-color="#3176d4"/>
						<stop offset="85%" stop-color="#3176d4"/>
						<stop offset="85.5%" stop-color="#2f70cc"/>
						<stop offset="86%" stop-color="#3176d4"/>
						<stop offset="95%" stop-color="#3176d4"/>
						<stop offset="95.5%" stop-color="#2f70cc"/>
						<stop offset="96%" stop-color="#3176d4"/>
					</radialGradient>
				</defs>

				<title>The Dock of the Bay</title>

				<g class="base">
					<rect fill="#5A6670" width="648" height="464" rx="12" ry="12"/>
					<circle fill="#071A2D" cx="274.13" cy="231.65" r="231.13"/>
				</g>

				<g class="record">
					<circle fill="#071A2D" cx="274.31" cy="231.69" r="8.64"/>
					<path fill="url(#grooves)" d="M274.33,5.54C149.45,5.54,48.21,106.78,48.21,231.67S149.45,457.79,274.33,457.79,500.46,356.55,500.46,231.67,399.22,5.54,274.33,5.54Zm0,234.79a8.64,8.64,0,1,1,8.64-8.64A8.64,8.64,0,0,1,274.31,240.33Z"/>
					<g clip-path="url(#clip-path)">
						<use transform="translate(150 60) scale(0.4)" xlink:href="#dock-of-bay-cover"/>
					</g>
				</g>

				<g class="arm">
					<image opacity="0.2" width="262" height="486" transform="translate(390 20)" xlink:href="https://public-619e3.firebaseapp.com/dock-of-the-bay/arm-shadow.png"></image>
					<path fill="#071A2D" d="M633.34,36.28a2.25,2.25,0,0,0-.49-0.49l-0.66-.47c-0.72-.51-1.64-1.13-2.75-1.83-0.74-.47-1.56-1-2.47-1.49s-1.89-1.07-3-1.64l-1.66-.85c-2.29-1.15-4.9-2.33-7.8-3.47q-1.09-.43-2.23-0.84-2.28-.83-4.78-1.6h0a90.86,90.86,0,0,0-25-3.81c-1.17,0-2.14,0-2.87.06a2.22,2.22,0,0,0-2,1.59l-0.23.77h0l-9.15,30.59-0.75,2.46-1.07,3.63,0,0.07a2.27,2.27,0,0,0,0,.31,2.18,2.18,0,0,0,.87,1.91,82.49,82.49,0,0,0,16.5,9L579.1,84.57a37.08,37.08,0,0,0-22.31,68.1l-8.58,26.21s-1.83,3.79-4.81,24.68l-13,122.53s-3.9,27.11-26,47.9l-14,12.79L487.13,383a1.25,1.25,0,0,0-1.76-.15l-11.79,10-3.33-4a2.48,2.48,0,0,0-3.48-.3L428,421.12c-0.2.17-19.19,23.59-25,30.75a2.46,2.46,0,0,0,0,3.22l15.69,18.71a2.46,2.46,0,0,0,3.17.53c8.07-4.48,34.43-19.12,34.64-19.29l38.81-32.57a2.48,2.48,0,0,0,.31-3.48l-3.43-4.09L504,404.83a1.25,1.25,0,0,0,.15-1.76l-2.87-3.38c4.16-3.11,42.54-32.83,46.08-73.12,3.57-40.62,12.65-122,12.65-122a241.09,241.09,0,0,1,11.47-43.08c0.35-1,.71-2,1.09-3a37.07,37.07,0,0,0,23.21-68.77c2.67-8.12,4.48-13.66,4.69-14.31a83.45,83.45,0,0,0,20,1.8A2.18,2.18,0,0,0,622.22,76a2.27,2.27,0,0,0,.16-0.27l0-.09,1.1-3.6,0.72-2.45L633.44,39h0l0.23-.77A2.22,2.22,0,0,0,633.34,36.28Z"/>
					<path fill="#071A2D" d="M633.67,38.24a2.22,2.22,0,0,0-.82-2.45,87.66,87.66,0,0,0-25.3-12.19h0a87.66,87.66,0,0,0-27.84-3.76,2.22,2.22,0,0,0-2,1.59l-0.23.77h0L566.44,59a2.27,2.27,0,0,0,0,.31,2.18,2.18,0,0,0,.87,1.91,87.66,87.66,0,0,0,25.3,12.19h0a87.66,87.66,0,0,0,27.84,3.76A2.18,2.18,0,0,0,622.22,76a2.27,2.27,0,0,0,.16-0.27L633.44,39h0Z"/>
					<path fill="#C0C2CC" d="M623.72,66.19A87.66,87.66,0,0,0,598.42,54h0a87.66,87.66,0,0,0-27.84-3.76,2.21,2.21,0,0,0-1.94,1.38l-1.11,3.63-1.07,3.64a2.27,2.27,0,0,0,0,.31,2.18,2.18,0,0,1,1.78-1.11,87.66,87.66,0,0,1,27.84,3.76h0A87.66,87.66,0,0,1,621.37,74a2.18,2.18,0,0,1,.87,1.91,2.27,2.27,0,0,0,.16-0.27L623.51,72l1.07-3.64A2.21,2.21,0,0,0,623.72,66.19Z"/>
					<path fill="#C0C2CC" d="M632.85,35.79a87.66,87.66,0,0,0-25.3-12.19h0a87.66,87.66,0,0,0-27.84-3.76,2.22,2.22,0,0,0-2,1.59l-8.36,28a2.42,2.42,0,0,1,1.66-.78,89.84,89.84,0,0,1,53.32,16,2.43,2.43,0,0,1,1,1.56l8.43-28A2.22,2.22,0,0,0,632.85,35.79Z"/>
					<path fill="#ECEFFF" d="M480.63,384.46h15.81a1,1,0,0,1,1,1v26.32a1,1,0,0,1-1,1H480.63a0,0,0,0,1,0,0V384.46A0,0,0,0,1,480.63,384.46Z" transform="translate(-141.77 410.63) rotate(-40.27)"/>
					<circle fill="#C0C2CC" cx="421.02" cy="456.41" r="8.51" transform="translate(-194.87 377.37) rotate(-40)"/>
					<circle fill="#C0C2CC" cx="429.48" cy="434.88" r="3.75" transform="translate(-179.05 377.77) rotate(-40)"/>
					<circle fill="#C0C2CC" cx="443.13" cy="451.15" r="3.75" transform="translate(-186.32 390.35) rotate(-40)"/>
					<path fill="#ECEFFF" d="M592.54,114.35a17.18,17.18,0,1,0,.47,13.14,17.2,17.2,0,0,0-.47-13.14h0Z"/>
					<path fill="#ECEFFF" d="M610.8,106.15a37.15,37.15,0,1,0-18.37,49.23A37.15,37.15,0,0,0,610.8,106.15Zm-15.44,22.28a19.6,19.6,0,1,1-.53-15A19.48,19.48,0,0,1,595.36,128.42Z"/>
				</g>

				<g class="cover">
					<use transform="scale(0.66)" xlink:href="#dock-of-bay-cover"/>
				</g>
			</svg>
		</div>
		<div class="media__body">
			<div class="media__lead text-meta">The Hit</div>
			<h2 class="media__title">The Dock of the Bay</h2>
			<p class="media__cta text-meta">
				<a href="#" data-play="dockOfBay">
					<span data-toggle-active>
						<svg width="25" height="25" viewBox="0 0 45 45" class="icon" xmlns="http://www.w3.org/2000/svg"><title>icon</title><path d="M22.5 45C10.074 45 0 34.926 0 22.5S10.074 0 22.5 0 45 10.074 45 22.5 34.926 45 22.5 45zm0-2C33.822 43 43 33.822 43 22.5S33.822 2 22.5 2 2 11.178 2 22.5 11.178 43 22.5 43z" fill-rule="nonzero"/><path d="M32.68 23.343L17.54 33.017A1 1 0 0 1 16 32.174V12.826a1 1 0 0 1 1.538-.843l15.143 9.674a1 1 0 0 1 0 1.686z"/></svg>
						Play
					</span>

					<span class="hidden" data-toggle-inactive>
						<svg width="25" height="25" viewBox="0 0 45 45" class="icon" xmlns="http://www.w3.org/2000/svg"><title>icon</title><path d="M22.5 45C10.074 45 0 34.926 0 22.5S10.074 0 22.5 0 45 10.074 45 22.5 34.926 45 22.5 45zm0-2C33.822 43 43 33.822 43 22.5S33.822 2 22.5 2 2 11.178 2 22.5 11.178 43 22.5 43z" fill-rule="nonzero"/><path d="M26 12h2a2 2 0 0 1 2 2v17a2 2 0 0 1-2 2h-2a2 2 0 0 1-2-2V14a2 2 0 0 1 2-2zM17 12h2a2 2 0 0 1 2 2v17a2 2 0 0 1-2 2h-2a2 2 0 0 1-2-2V14a2 2 0 0 1 2-2z"/></svg>
						Pause
					</span>
				</a>
				<audio preload="auto" data-song="dockOfBay">
					<source src="https://public-619e3.firebaseapp.com/dock-of-the-bay/dock-of-the-bay.mp3" type="audio/mpeg">
				</audio>
			</p>
		</div>
	</div>
</div>
            
          
!
            
              // Imports
@import url('https://fonts.googleapis.com/css?family=Playfair+Display:900');
@import url('https://fonts.googleapis.com/css?family=Montserrat:500,700|Playfair+Display:900');

// Base styles
*,
*:before,
*:after {
  box-sizing: inherit;
}

/**
 * Remove the gap between audio, canvas, iframes,
 * images, videos and the bottom of their containers:
 * https://github.com/h5bp/html5-boilerplate/issues/440
 */

audio,
canvas,
iframe,
img,
svg,
video {
	vertical-align: middle;
}

/**
 * Correct overflow not hidden in IE 9/10/11.
 */

svg:not(:root) {
	overflow: hidden;
}

// Vars
$base-spacing: 1em;
$transition-duration: .3s;
$transition-timing: ease-in-out;
$off-white: #ECEFFF;
$base-link-color: #C1A367;
$hover-link-color: darken($base-link-color, 10%);
$base-accent-color: $base-link-color;
$text-color: #071A2D;
$header-line-height: 1.2;
$base-line-height: 1.4;
$small: "(min-width: 40em)";
$large: "(min-width: 60em)";

// Global Styles
body {
	background: $off-white url(https://public-619e3.firebaseapp.com/dock-of-the-bay/texture.png) repeat;
	color: $text-color;
	font-family: 'Montserrat', sans-serif;
}

a {
	color: $base-link-color;
	text-decoration: none;
	transition: color $transition-duration $transition-timing;

	&:hover {
		color: $hover-link-color;
	}

	&:focus {
		outline: none;
	}

	&:active,
	&:focus {
		color: $hover-link-color;
	}
}

h1,
h2,
h3 {
	font-family: 'Playfair Display', serif;
	line-height: $header-line-height;
}


// Helpers
.hidden {
	display: none !important;
}

.icon {
	display: inline-block;
	vertical-align: middle;
	transition: fill $transition-duration $transition-timing;

	a & {
		fill: $base-link-color;
	}

	a:hover & {
		fill: $hover-link-color;
	}
}


// Container
.container {
	max-width: 80em;
	margin: 0 auto;
	padding: $base-spacing;
}


// Media Object
.media {
	@media #{$small} {
		display: flex;
		align-items: center;
		flex-direction: row;
	}
}

.media__item {
	@media #{$small} {
		flex: 4 0 0%;
	}

	// Fallback for ie 10-11
	@media screen and (-ms-high-contrast: active), screen and (-ms-high-contrast: none) {
		position: relative;
		height: 0;
		width: 100%;
		padding: 0 0 50%;
	}

	svg {
		// Adjust for overflow items
		padding: $base-spacing 0;

		// Fallback for ie 10-11
		@media screen and (-ms-high-contrast: active), screen and (-ms-high-contrast: none) {
			position: absolute;
			height: 100%;
			width: 100%;
			left: 0;
			top: 0;
		}
	}
}

.media__body {
	text-align: center;

	@media #{$small} {
		flex: 2 0 0%;
		padding: 0 0 0 $base-spacing*2;
		text-align: left;
	}
}

.media__lead {
	font-size: ms(-2);
	color: $base-accent-color;
	text-transform: uppercase;
	letter-spacing: 0.2em;
	font-size: 0.75em;
}

.media__title {
	margin: 0 0 $base-spacing/2;
	font-size: 2em;
	line-height: $header-line-height;

	@media #{$small} {
		font-size: 2em;
	}
	
	@media #{$large} {
		font-size: 3em;
	}
}

.media__desc {
	margin: 0;
	font-size: ms(-1);

	@media #{$large} {
		font-size: ms(0);
	}
}

.media__link {
	display: block;
	margin-top: $base-spacing;

	svg {
		margin-left: $base-spacing/3;
		transition: transform $transition-duration $transition-timing;
	}

	&:hover {
		svg {
			transform: translateX(10%);
		}
	}
}

.media__cta {
	margin: 0;
	font-size: 1.2em;
	line-height: 1;
	font-weight: 500;
}

// Scene
#dockOfBay {
	.base,
	.arm {
		opacity: 1;

		@media #{$small} {
			opacity: 0;
		}
	}

	.cover {
		opacity: 0;

		@media #{$small} {
			opacity: 1;
		}
	}
}
            
          
!
            
              // Classes
var activeClass = 'is-active';
var inactiveClass = 'is-inactive';

// Greensock Tweens
var tweens = {
	dockOfBay: {
		toggle: document.querySelector('[data-play="dockOfBay"]'),
		audio: document.querySelector('[data-song="dockOfBay"]'),
		animation: new TimelineMax(),
		scene: document.querySelector('#dockOfBay')
	}
};

// Get closets matching parent
var getClosest = function (elem, selector) {
	var firstChar = selector.charAt(0);
	for ( ; elem && elem !== document; elem = elem.parentNode ) {
		if ( firstChar === '.' ) {
			if ( elem.classList.contains( selector.substr(1) ) ) {
				return elem;
			}
		}
		if ( firstChar === '#' ) {
			if ( elem.id === selector.substr(1) ) {
				return elem;
			}
		}
		if ( firstChar === '[' ) {
			if ( elem.hasAttribute( selector.substr(1, selector.length - 2) ) ) {
				return elem;
			}
		}
		if ( elem.tagName.toLowerCase() === selector ) {
			return elem;
		}
	}
	return false;
};

// Pause active songs
var pauseMusic = function(elem) {
	if(elem) {
		for(var key in tweens) {
			if (!tweens[key].audio.paused && tweens[key].audio !== elem) {
				tweens[key].audio.pause();
			}
		}
	} else {
		for(key in tweens) {
			if (!tweens[key].audio.paused) {
				tweens[key].audio.pause();
			}
		}
	}
};

// Pause active animations
var pauseAnimation = function(elem) {
	if (elem) {
		for(var key in tweens) {
			if (tweens[key].animation && tweens[key].animation.isActive() && key !== elem) {
				tweens[key].animation.pause();
				updateToggle(tweens[key].toggle);
			}
		}
	} else {
		for(key in tweens) {
			if (tweens[key].animation && tweens[key].animation.isActive()) {
				tweens[key].animation.pause();
				updateToggle(tweens[key].toggle);
			}
		}
	}
};

// Toggle animation state
var toggleAnimation = function(elem) {
	if (tweens[elem].animation) {

		// If animation is active
		if(tweens[elem].animation.isActive()) {

			// Pause animation
			tweens[elem].animation.pause();

		// If animation is paused
		} else if (tweens[elem].animation.paused()) {

			// Resume animation
			tweens[elem].animation.resume();

		// If animation was not be initiated
		} else {

			// Init animation
			recordTweenInit(tweens[elem].scene, tweens[elem].animation);
		}
	}
};

// Toggle Song
var toggleSong = function(toggle, elem) {

	// Pause any music playing
	pauseMusic(elem);

	// Toggle state of selected track
	if (elem.paused) {
		elem.play();
		toggle.classList.remove(inactiveClass);
	} else {
		elem.pause();
		toggle.classList.add(inactiveClass);
	}
};

// Update song toggle element
var updateToggle = function(toggle) {

	// Get child elements
	var activeToggle = toggle.querySelector('[data-toggle-active]');
	var inactiveToggle = toggle.querySelector('[data-toggle-inactive]');

	// Toggle states
	activeToggle.classList.toggle('hidden');
	inactiveToggle.classList.toggle('hidden');
};

// Handle click events
var clickEventHandler = function(e) {

		// Get closest anchor
		var anchor = getClosest( e.target, 'a' );
	
		// Music/animation trigger
		if (anchor && anchor.hasAttribute('data-play')) {

			// Prevent link default
			e.preventDefault();

			// Get song name
			var name = anchor.getAttribute('data-play');

			// Pause All Animations
			pauseAnimation(name);

			// Toggle song audio
			toggleSong(anchor, tweens[name].audio);

			// Play, pause or init animation
			toggleAnimation(name);

			// Update toggle
			updateToggle(tweens[name].toggle);
		}
	};

// Handle end events
var endedEventHandler = function(e) {

	// Get audio ID
	var audio = e.target;
	var name = audio.getAttribute('data-song');

	// Reset corresponding animation scene
	tweens[name].animation.restart().pause();

	// Update toggle
	updateToggle(tweens[name].toggle);
};

// Record player animation
var recordTweenInit = function(sceneEl, tweenName) {

	// Get DOM elements
	var cover = sceneEl.querySelector('.cover');
	var base = sceneEl.querySelector('.base');
	var arm = sceneEl.querySelector('.arm');
	var record = sceneEl.querySelector('.record');

	// Animate elements
	tweenName.to(cover, 1, {x: '-=150%', ease: Power2.easeOut})
	.to(base, 0.5, {opacity: 1, ease: Power2.easeOut}, '-=1')
	.to(arm, 0.5, {rotation: '8deg', opacity: 1, transformOrigin: 'right 15%', ease: Power2.easeOut}, '-=1')
	.to(record, 1.5, {rotation: 360, transformOrigin: 'center center', repeat:-1, ease: Power0.easeNone}, '0.5')
	.to(arm, 400, {rotation: '30deg', transformOrigin: 'right 10%', ease: Power2.easeOut, delay: 2}, '0');
};

// Listen for click event
window.addEventListener('click', clickEventHandler, false);

// Listen for ended event
for(var key in tweens) {
	tweens[key].audio.addEventListener('ended', endedEventHandler, false);
}
            
          
!
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