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 id="frame" class="fit">
		<div id="buttons" class="flexc outside-frame">
			<button id="add">Add to end</button>
			<button id="remove">Remove from middle</button>
		</div>
		<div id="struc" class="flexc">
			<div class="sphere"></div>
		</div>
		<div id="angles" class="flexc outside-frame">
		</div>
	</div>
	<span id="credit">Photo sourced from <a href="https://unsplash.com/">Unsplash.com</a></span>
</div>
              
            
!

CSS

              
                #frame {
	z-index: 2;
	width: 60%;
	height: 60%;
	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);
	overflow: hidden;
}

.flexc {
	display: flex;
	justify-content: space-evenly;
	align-items: center;
	width: 100%;
}

#struc {
	height: 100%;
	z-index: -1;
	pointer-events: none;
}

#struc::after {
	content: "";
	position: absolute;
	top: 0; bottom: 0;
	left: 0; right: 0;
	margin: auto;
	width: 12px;
	height: 12px;
	border-radius: 6px;
	background-color: rgba(15, 9, 33, 0.8);
}

.sphere {
	width: 6vw;
	height: 6vw;
	margin-right: 12vw;
	border-radius: 100%;
	background-color: rgb(222, 233, 255);
	box-shadow:
		inset -0.6vw -0.6vw 3vw 0.15vw rgba(0, 0, 0, 0.9),
		0.6vw 0.6vw 1.8vw -0.1vw rgba(0, 0, 0, 0.6);
}

.outside-frame { position: absolute; }

#buttons { top: 1em; }

#angles {
	justify-content: center;
	bottom: 1em;
}

#angles > span {
	margin: 0 1em;
	font-weight: bold;
}


/* Prep */

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

#main {
	position: relative;
	width: 100%;
	height: 100%;
	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;
}

button {
	padding: 0.5em 1em;
	border: none;
	border-radius: 4px;
	background-color: rgb(50, 60, 80);
	font: inherit;
	color: rgb(188, 200, 222);
	text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.85);
	box-shadow:
		0.04em 0.06em 0.2em 0.02em rgba(0, 0, 0, 0.7),
		inset -0.25em -0.35em 1em -0.4em rgba(0, 0, 0, 1),
		inset 0.25em 0.35em 1em -0.4em rgba(255, 255, 255, 0.8);
	-webkit-appearance: none;
	appearance: none;
	outline: none;
	cursor: pointer;
	transition: box-shadow 0.2s linear, transform 0.2s ease;
}

button:hover, button:focus {
	transform: scale(1.05);
}

button:active {
	box-shadow:
		0 0 0.1em 0.02em rgba(0, 0, 0, 0.4),
		inset 0.1em 0.15em 0.6em -0.15em rgba(0, 0, 0, 1),
		inset -0.1em -0.15em 0.6em -0.15em rgba(255, 255, 255, 0.8);
	transform: scale(0.97);
	transition: none;
}

button:disabled {
	opacity: 0.6;
	transform: none !important;
	pointer-events: none;
}
              
            
!

JS

              
                console.clear();
objectFitImages();

const S = Sizzle,
		struct = S('#struc')[0],
		sphere = S('.sphere')[0],
		anglesElement = S('#angles')[0],
		tlArray = [],
		infoArray = [],
		addBtn = S('#add')[0],
		remBtn = S('#remove')[0];

let index = 0;

for ( let i = 0; i < 3; i++ ) {
	addTL();
}

function addTL() {
	// Get a random angle
	const a = Math.round(Math.random() * 360);
	
	// Add it to the list at the bottom
	insertAngleInfo(a);
	
	tlArray.push(
		// The trick here is that each element in the array is a function that creates a new timeline which will only play once.
		// We do this because otherwise everything would be stored at the start and it would be cumbersome to have to readjust to changes in the array.
		// This way, every time this element is called, the new timeline will be correct by default (since it's new, not a previously created version).
		
		function() {
			const tl = new TimelineLite({onComplete: startNextTL});

			tl.to(struct, 1.5, {rotation: a + '_cw', ease: Power2.easeInOut})
			  .to(sphere, 1.5, {rotation: -a + '_ccw', ease: Power2.easeInOut}, 0);
			
			// info stuff
			tl.to(infoArray[index], 0.25, {scale: 1.25}, 0)
			  .to(infoArray[index - 1 < 0 ? infoArray.length - 1 : index - 1], 0.25, {scale: 1}, 0);
		}
	);
	
	remBtn.disabled = false;
};

function startNextTL() {
	index++;
	if ( index >= tlArray.length ) { index = 0; }
	tlArray[index]();
}

// Here we call the first function in the array, which will start the first TL
tlArray[0]();

// Removing timelines...
function removeTL() {
	let remove = Math.ceil((tlArray.length - 1) / 2);
	
	// You need a mechanism to avoid removing what's currently playing, here I'm just removing the TL just before if that happens
	if ( remove === index ) { remove--; }
	
	tlArray.splice(remove, 1);
	
	if ( tlArray.length < 3 ) { remBtn.disabled = true; }
	
	// info stuff
	removeAngleInfo(remove);
}

// Below is button and info handling

function insertAngleInfo(angle) {
	const info = document.createElement('span');
	info.textContent = angle + '°';
	anglesElement.appendChild(info);
	
	infoArray.push(info);
}

function removeAngleInfo(index) {
	anglesElement.removeChild(infoArray[index]);
	infoArray.splice(index, 1);
}

addBtn.addEventListener('click', addTL);
remBtn.addEventListener('click', removeTL);
              
            
!
999px

Console