HTML preprocessors can make writing HTML more powerful or convenient. For instance, Markdown is designed to be easier to write and read for text documents and you could write a loop in Pug.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. So you don't have access to higher-up elements like the <html>
tag. If you want to add classes there that can affect the whole document, this is the place to do it.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. If you need things in the <head>
of the document, put that code here.
The resource you are linking to is using the 'http' protocol, which may not work when the browser is using https.
CSS preprocessors help make authoring CSS easier. All of them offer things like variables and mixins to provide convenient abstractions.
It's a common practice to apply CSS to a page that styles elements such that they are consistent across all browsers. We offer two of the most popular choices: normalize.css and a reset. Or, choose Neither and nothing will be applied.
To get the best cross-browser support, it is a common practice to apply vendor prefixes to CSS properties and values that require them to work. For instance -webkit-
or -moz-
.
We offer two popular choices: Autoprefixer (which processes your CSS server-side) and -prefix-free (which applies prefixes via a script, client-side).
Any URLs added here will be added as <link>
s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.
You can apply CSS to your Pen from any stylesheet on the web. Just put a URL to it here and we'll apply it, in the order you have them, before the CSS in the Pen itself.
You can also link to another Pen here (use the .css
URL Extension) and we'll pull the CSS from that Pen and include it. If it's using a matching preprocessor, use the appropriate URL Extension and we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
JavaScript preprocessors can help make authoring JavaScript easier and more convenient.
Babel includes JSX processing.
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.
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
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.
Using packages here is powered by esm.sh, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ESM usage.
All packages are different, so refer to their docs for how they work.
If you're using React / ReactDOM, make sure to turn on Babel for the JSX processing.
If active, Pens will autosave every 30 seconds after being saved once.
If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.
If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.
Visit your global Editor Settings.
<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>
<a class="suppoprt-me" href="https://www.buymeacoffee.com/marioduarte" target="_blank"><img src="https://img.buymeacoffee.com/button-api/?text=Buy me a Coffee &emoji=&slug=marioduarte&button_colour=FF5F5F&font_colour=ffffff&font_family=Cookie&outline_colour=000000&coffee_colour=FFDD00"></a>
// 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://raw.githubusercontent.com/Mario-Duarte/CodePen/main/assets/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;
}
}
}
}
}
.suppoprt-me {
display: inline-block;
position: fixed;
bottom: 10px;
left: 10px;
width: 20vw;
max-width: 250px;
min-width: 200px;
z-index: 9;
img {
width: 100%;
height: auto;
}
}
//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);
Also see: Tab Triggers