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. 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

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

              
                <div id="main">
	<img id="image" class="fit" src="https://source.unsplash.com/random">
	<div class="frame expo">
		<div class="struc">
			<div id="sphExpo" class="sphere"></div>
		</div>
	</div>
	<div class="frame exposcale">
		<div class="struc">
			<div id="sphExpoScale" class="sphere"></div>
		</div>
	</div>
	<div class="frame linear">
		<div class="struc">
			<div id="sphLinear" class="sphere"></div>
		</div>
	</div>
	<div class="frame sideview">
		<div class="struc">
			<div id="camera"></div>
			<div id="sphSview" class="sphere"></div>
		</div>
	</div>
	<span id="credit">Photo sourced from <a href="https://unsplash.com/">Unsplash.com</a></span>
</div>
              
            
!

CSS

              
                .frame {
	flex: 1 1 auto;
	position: relative;
	z-index: 2;
	height: 24vh;
	margin: 2.5vw;
	border: 6px solid rgba(222, 233, 255, 0.9);
	color: rgb(15, 9, 33);
	background-color: rgba(222, 233, 255, 0.8);
	box-shadow:
		inset 0 0 30px rgba(15, 9, 33, 0.3),
		0 0 18px rgba(222, 233, 255, 0.6);
}

.frame.sideview {
	flex: 3 1 100%;
}

.struc {
	display: flex;
	justify-content: space-evenly;
	align-items: center;
	position: relative;
	width: 100%;
	height: 100%;
	overflow: hidden;
}

.sphere {
	z-index: 2;
	width: 8vh;
	height: 8vh;
	border-radius: 100%;
	background-color: rgb(222, 233, 255);
	box-shadow:
		inset -0.8vh -0.8vh 4vh 0.2vh rgba(0, 0, 0, 0.9),
		0.8vh 0.8vh 2.5vh -0.1vh rgba(0, 0, 0, 0.6);
}

#sphSview {
	position: absolute;
}

#camera {
	border: 1px solid transparent;
	border-left-width: 0;
	border-right: 1px solid rgba(88, 122, 188, 0.5);
}

.frame::after {
	display: block;
	position: absolute;
	top: -1.8em;
	width: 100%;
	color: rgb(222, 233, 255);
	text-align: center;
	font-size: 1.2em;
	font-weight: bold;
}

.frame.expo::after {
	content: "Custom/Expo";
}

.frame.exposcale::after {
	content: "ExpoScale";
}

.frame.linear::after {
	content: "Linear";
}

.frame.sideview::after {
	content: "Side view – spheres turn pink when they grow taller than the 'fov'";
	font-weight: normal;
	top: calc(100% + 0.6em);
}

/* Prep */

body { height: 100vh; width: 100vw; margin: 0; }

#main {
	display: flex;
	justify-content: center;
	align-items: center;
	align-content: center;
	flex-wrap: wrap;
	position: relative;
	width: 100%;
	height: 100%;
	padding: 5vw;
	box-sizing: border-box;
	overflow: hidden;
	color: rgba(222, 233, 255, 0.8);
	background-color: rgb(15, 9, 33);
	font-family: "Trebuchet MS", "Lucida Sans Unicode", "Tahoma", sans-serif;
}

.fit {
	position: absolute;
	top: 0; right: 0; bottom: 0; left: 0;
	margin: auto;
}

#image {
	width: 100%;
	height: 100%;
	object-fit: cover;
	font-family: 'object-fit: cover;';
	opacity: 0.4;
	filter: blur(4px);
}

#credit {
	position: absolute;
	bottom: -1em;
	right: -1em;
	padding: 0.5em 1.7em 1.5em 0.7em;
	border-radius: 0.5em;
	background-color: rgba(15, 9, 33, 0.8);
	text-align: right;
}

#credit > a {
	color: rgba(222, 233, 255, 0.8) !important;
}
              
            
!

JS

              
                console.clear();
objectFitImages();

const S = Sizzle,
      frameSv = S('.frame.sideview')[0],
      camera = S('#camera')[0],
		spheres = S('.sphere'),
      sphExpo = S.matches('#sphExpo', spheres),
      sphExpoScale = S.matches('#sphExpoScale', spheres),
      sphLinear = S.matches('#sphLinear', spheres),
      sphSview = S.matches('#sphSview', spheres),
      tl = new TimelineMax({paused: true}),
      tlSview = new TimelineMax({paused: true}),
		tlMeta = new TimelineMax({delay: 1, repeat: -1, repeatDelay: 1, onRepeat: checkResize})
      fillStatus = {
			sphExpo: false,
			sphExpoScale: false,
			sphLinear: false };

// Set default eases
TweenLite.defaultEase = Linear.easeNone;
CustomEase.create('zoom', 'M0,0 C0,0 0.6,0 0.8,0.33333 1,0.65 1,1 1,1');

// timeline machine
function buildTL(element, easeA, easeB) {
	return new TimelineMax({paused: true, onUpdate: checkFill, onUpdateParams: element})
		.to(element, 1, {scale: 8, ease: easeA})
		.to(element, 1, {scale: 1, ease: easeB}, 2);
}

function checkFill(el) {
	let h = el.getBoundingClientRect().height;
	if ( fillStatus[el.id] ) {
		if (h < frameSv.clientHeight) {
			TweenLite.set(el, {backgroundColor: 'rgb(222, 233, 255)'});
			fillStatus[el.id] = false;
		}
	} else {
		if (h > frameSv.clientHeight) {
			TweenLite.set(el, {backgroundColor: 'rgb(255, 111, 188)'});
			fillStatus[el.id] = true;
		}
	}
}

// Set up the  side view
const fillT = 16 / 21;
TweenLite.set(camera, {scaleX: frameSv.clientWidth / 2, scaleY: 0.4 * frameSv.clientHeight});
TweenLite.set(sphSview, {scale: 0.8});
tlSview.fromTo(sphSview, 1, {x: frameSv.clientWidth / 4}, {x: -3 * frameSv.clientWidth / 16})
       .to(sphSview, 1, {x: frameSv.clientWidth / 4}, 2)
       .set(sphSview, {backgroundColor: 'rgb(255, 111, 188)'}, fillT)
       .set(sphSview, {backgroundColor: 'rgb(222, 233, 255)'}, 3 - fillT);

// Create global timeline
tl.add(buildTL(sphExpo, 'zoom', Expo.easeOut).tweenFromTo(0, 3))
  .add(buildTL(sphExpoScale, ExpoScaleEase.config(1, 8), ExpoScaleEase.config(8, 1, Linear.easeNone)).tweenFromTo(0, 3), 0)
  .add(buildTL(sphLinear, Linear.easeNone, Linear.easeNone).tweenFromTo(0, 3), 0)
  .add(tlSview.tweenFromTo(0, 3), 0);

// Create meta timeline
tlMeta.add(tl.tweenFromTo(0, fillT, {ease: Power1.easeInOut}))
      .add(tl.tweenFromTo(fillT, 1, {ease: Power1.easeInOut, immediateRender: false}).timeScale(0.5), 2)
      .add(tl.tweenFromTo(1, 3, {ease: Power1.easeInOut, immediateRender: false}));

// Handle resizing
let resized = false;
function checkResize() {
	if ( resized ) {
		resized = false;
		TweenLite.set(camera, {scaleX: frameSv.clientWidth / 2, scaleY: 0.4 * frameSv.clientHeight});
		tlSview.invalidate();
	}
}

window.addEventListener('resize', () => { resized = true; });
              
            
!
999px

Console