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 is required to process package imports. If you need a different preprocessor remove all packages first.

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

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 class="container">
	<div class="inner">
		
		<div class="thumb js-thumb">
			<div class="backlight js-back-light"></div>
			<div class="player js-player"></div>
			<div class="shine js-shine"></div>
			<!--<div class="btn-shadow js-btn-shadow"></div>-->
			<div class="btn js-btn"></div>
		</div>
		
	</div>
</div>

<div class="info">
	<p class="more-info js-more-info">More info</p>
	<h1>3D Video Thumbnail</h1>
	<p class="small">by: <a href="https://www.mariodesigns.co.uk/" target="_blank">Mario Duarte</a></p>
	
	<ul class="social">
		<li class="item"><a href="https://twitter.com/MDesignsuk" target="_blank"><i class="fa fa-twitter"></i></a></li>
		<li class="item"><a href="https://github.com/Mario-Duarte/" target="_blank"><i class="fa fa-github"></i></a></li>
		<li class="item"><a href="https://bitbucket.org/Mario_Duarte/" target="_blank"><i class="fa fa-bitbucket"></i></a></li>
		<li class="item"><a href="https://codepen.io/MarioDesigns/" target="_blank"><i class="fa fa-codepen"></i></a></li>
		<li class="item"><a href="https://dribbble.com/MDesignsuk" target="_blank"><i class="fa fa-dribbble" aria-hidden="true"></i></a></li>
		<li class="item"><a href="https://www.behance.net/mdesignsuk" target="_blank"><i class="fa fa-behance" aria-hidden="true"></i></a></li>
	</ul>
	
</div>
              
            
!

CSS

              
                // Set variables
$max-width: 960px;

// set body style and normalizer
html,body {
	height: 100%;
	position: relative;
}

body {
	padding: 0;
	margin: 0;
	font-family: 'helvetica', sans-serif;
	background: darken(#2c3e50, 10%);
}

// Main container styles
.container {
	position: relative;
	width: 100%;
	height: 100%;
	display: flex;
	flex-direction: row;
	flex-wrap: wrap;
	justify-content: center;
	align-items:center;
	padding: 20px;
	box-sizing: border-box;
	.inner {
		position: relative;
		width: 100%;
		height: 100%;
		max-width: $max-width;
		display: flex;
		flex-direction: row;
		flex-wrap: wrap;
		justify-content: center;
		align-items:center;
		perspective: 300px;
		background: radial-gradient(ellipse at center, rgba(255,255,255,0.15) 0%,rgba(255,255,255,0) 70%);
	}
}

// Main styles for the 3D thumb
.thumb {
	position: relative;
	width: 320px;
	height: 180px;
	box-sizing: border-box;
	transform-style: preserve-3d;
	transform-origin: center;
	transition: all 0.2s linear;
	transform: rotatex(0deg) rotatey(0deg);
	
	&.idle {
		&:after {
			transform: translatez(25px) translatey(0px);
			opacity: 1;
		}
		&:before {
			transform: translatez(25px) translatey(0px);
			opacity: 1;
		}
	}
	
	&:after {
		content: 'Hover Me';
		font-size: 12px;
		color: silver;
		position: absolute;
		top: -55px;
		left: 50%;
		width: 80px;
		margin-left: -40px;
		background-color: rgba(255,255,255,0.4);
		text-align: center;
		padding: 5px 0;
		border-radius: 3px;
		transform: translatez(25px) translatey(20px);
		transition: all 0.4s ease-in-out;
		opacity: 0;
	}
	&:before {
		content: '';
		position: absolute;
		top: -32px;
		left: 50%;
		margin-left: -10px;
		width: 0;
		height: 0;
		border-style: solid;
		border-width: 8px 10px 0 10px;
		border-color: rgba(255,255,255,0.4) transparent transparent transparent;
		transform: translatez(25px) translatey(20px);
		transition: all 0.4s ease-in-out;
		opacity: 0;
	}
	
	.backlight {
		position: absolute;
		top: 0;
		left: 0;
		right: 0;
		width: 320px;
		height: 180px;
		background-color: rgba(255,255,255,0.1);
		box-shadow: 0px 0px 100px 40px rgba(255,255,255,0.2);
		transform: translateZ(-40px);
		z-index: 1;
	}
	
	.player {
		position: absolute;
		top: 0;
		left: 0;
		right: 0;
		bottom: 0;
		width: 320px;
		height: 180px;
		opacity: 1;
		border-radius: 5px;
		background-color: black;
		background-image: url('https://s3-us-west-2.amazonaws.com/s.cdpn.io/751678/alien-world.jpg');
		background-repeat: no-repeat;
		background-position: center;
		background-size: cover;
		transform: translateZ(20px);
		z-index: 2;
	}
	
	.shine {
		position: absolute;
		top: 0;
		left: 0;
		width: 320px;
		height: 180px;
		border-radius: 5px;
		//background-color: rgba(255,255,255,1);
		//background: radial-gradient(ellipse at 50% 50%, rgba(255,255,255,0.6) 0%,rgba(51,51,51,0) 100%);
		transform: translateZ(20px);
		overflow: hidden;
		pointer-events: none;
		z-index: 3;
	}
	
// ==============================================================
// MOVED -> moved all of this to a pseudo element of the play icon	
// 	.btn-shadow {
// 		position: absolute;
// 		top: 50%;
// 		left: 50%;
// 		margin-left: -21px;
// 		margin-top: -21px;
// 		width: 42px;
// 		height: 42px;
// 		border-radius:50%;
// 		background-color: rgba(0,0,0,0.3);
// 		box-shadow: 0 0 20px 5px rgba(0,0,0,0.5);
// 		transform: translateZ(50px);
// 		z-index: 4;
// 	}
	
	.btn {
		position: absolute;
		top: 50%;
		left: 50%;
		margin-left: -21px;
		margin-top: -21px;
		width: 42px;
		height: 42px;
		border-radius:50%;
		opacity: 0.8;
		border: 2px solid rgba(255,255,255,0.8);
		background-color: #34495e;
		transform: translateZ(60px);
		transition: opacity 0.2s ease-in-out;
		cursor: pointer;
		z-index: 5;
		&:hover {
			opacity: 1;
		}
		&:after {
			content: '';
			position: absolute;
			top: 50%;
			left: 50%;
			width: 0;
			height: 0;
			margin-left: -5px;
			margin-top: -7px;
			border-style: solid;
			border-width: 7.5px 0 7.5px 14px;
			border-color: transparent transparent transparent rgba(255,255,255,0.6);
			z-index: 5;
		}
		&:before {
			content: '';
			position: absolute;
			top: 50%;
			left: 50%;
			margin-left: -21px;
			margin-top: -21px;
			width: 42px;
			height: 42px;
			border-radius:50%;
			background-color: rgba(0,0,0,0.3);
			box-shadow: 0 0 20px 5px rgba(0,0,0,0.5);
			transform: translateZ(50px);
			z-index: 4;
		}
	}
	
}

// Info section at the bottom
.info {
	position: fixed;
	bottom: 40px;
	left: 50%;
	margin-left: -160px;
	width: 320px;
	text-align: center;
	transform: translatey(120px);
	transition: transform 0.4s ease-in-out;
	z-index: 1;
	
	&.open {
		transform: translatey(0px);
	}
	
	p.more-info {
		display: inline-block;
		color: silver;
		background-color: rgba(0,0,0,0.4);
		padding: 5px 10px;
		border-radius: 3px;
		margin: 0 0 30px 0;
		cursor: pointer;
	}
	
	h1 {
		font-size: 20px;
		font-weight: lighter;
		color: silver;
		text-transform: uppercase;
		margin: 0;
	}
	
	p.small {
		font-size: 12px;
		color: silver;
		margin: 5px 0;
		a {
			color: #2980b9;
			text-decoration: none;
			transition: color 0.4s ease-in-out;
			&:hover { color: #3498db; }
		}
	}
	
	ul.social {
		width: 100%;
		margin: 20px 0 0 0;
		padding: 0;
		display: flex;
		flex-direction: row;
		flex-wrap: wrap;
		justify-content: center;
		
		li.item {
			padding: 0 10px;
			list-style: none;
			margin: 0;
			a {
				color: silver;
				text-decoration: none;
				&:hover {
					color: #3498db;
				}
			}
		}
		
	}
	
}
              
            
!

JS

              
                //Sets Variables
var thumb = $('.js-thumb');
var shine = $('.js-shine');
var moreInfo = $('.js-more-info');
var hovered = false;

//Event Listner waiting for the mouse to enter the div .thumb
thumb.on('mousemove', function(e){
	
	//set the hovered var to true
	hovered = true;
	
	//on hover if thumb has class idle removes it
	if ( $(this).hasClass('idle') ) {
		$(this).removeClass('idle');
	}
	
	// Define vars
	//gets the half point horizontally
	var hCenter = $(this).width() / 2;
	//gets the half point vertically
	var vCenter = $(this).height() / 2;
	//gets the x coord of the pointer
	var relativeX = (e.pageX - $(this).offset().left);
	//gets the y coords of the pointer
	var relativeY = (e.pageY - $(this).offset().top);
	//calculates the x rotation
	var xRotation = ( relativeY - vCenter ) * 0.1;
	//calculates the y rotation
	var yRotation = ( relativeX - hCenter ) * 0.05;
	//calculates the x-offset of the shine
	var xShine = ( relativeX * 100 ) / $(this).width();
	//calculates the y-offset of the shine
	var yShine = ( relativeY * 100 ) / $(this).height();
	
	//Invert x and y offset
	xShine = 100 - xShine;
	yShine = 100 - yShine;
	
	//var coords = [{xcord:xShine,ycod:yShine}]
	//console.table(coords);
	
	//Apply rotation to the element
	$(this).css({ transform : 'rotatex('+xRotation+'deg) rotatey('+yRotation+'deg)' });
	
	//Apply the shine to the element
	$('.js-shine').css({ background: 'radial-gradient(ellipse at '+xShine+'% '+yShine+'%, rgba(255,255,255,0.4) 0%,rgba(51,51,51,0) 60%)' });
	
});

//on the mouse leave reset the thumb
thumb.on('mouseleave', function(){
	$(this).css({ transform : 'rotatex(0deg) rotatey(0deg)' });
	$('.js-shine').css({ background: 'none' });
});

//event listner waiting for a click on the more info btn
moreInfo.on('click', function(){
	var info = $('.info');
	$('.info').toggleClass('open');
	if ( info.hasClass('open') ) {
		$(this).html('Less info');
	} else {
		$(this).html('More info');
	}
});

//After xs if no interaction was made with the thumbnail adds in a little helper with what to do, this should disapear after you mouse on the thumb
setTimeout(function(){
	if( hovered == false ) {
		thumb.addClass('idle');
	}
},8000);
              
            
!
999px

Console