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=play-trigger></div>
<div class=hand-wrapper>
<div class=hand>
<div class=card>
<div class=front>Front</div>
<div class=back>Back</div>
</div>
<div class=card>
<div class=front>Front</div>
<div class=back>Back</div>
</div>
<div class=card>
<div class=front>Front</div>
<div class=back>Back</div>
</div>
<div class=card>
<div class=front>Front</div>
<div class=back>Back</div>
</div>
<div class=card>
<div class=front>Front</div>
<div class=back>Back</div>
</div>
<div class=card>
<div class=front>Front</div>
<div class=back>Back</div>
</div>
<div class="card">
<div class=front>Front</div>
<div class=back>Back</div>
</div>
</div>
</div>
@import "bourbon";
/**\
|**| Constants
\**/
$debug: true; // <insert description>
$card-width: 7em; // <insert description>
$card-height: ($card-width * 1.4); // <insert description>
$max-hand-size: 10; // <insert description>
$fanning-angle: -3deg; // <insert description>
$hand-gutter: 60px; // <insert description>
$bottom-shadow-color: black; // <insert description>
$top-shadow-color: black; // <insert description>
/**\
|**| Mixins
\**/
// Material Shadow mixin
// @credit: CSS-Tricks
// @link: https://css-tricks.com/snippets/sass/material-shadows-mixin/
/**
* Computes a top-shadow for a card effect.
*
* @param {Number} $depth - depth level
*
* @return {List}
*/
@function top-shadow($depth) {
$primary-offset: nth(1.5 3 10 14 19, $depth) * 1px;
$blur: nth(1.5 3 10 14 19, $depth) * 4px;
$color: rgba($top-shadow-color, nth(.12 .16 .19 .25 .30, $depth));
@return 0 $primary-offset $blur $color;
}
/**
* Computes a bottom-shadow for a card effect.
*
* @param {Number} $depth - depth level
*
* @return {List}
*/
@function bottom-shadow($depth) {
$primary-offset: nth(1.5 3 6 10 15, $depth) * 1px;
$blur: nth(1 3 3 5 6, $depth) * 4px;
$color: rgba($bottom-shadow-color, nth(.24 .23 .23 .22 .22, $depth));
@return 0 $primary-offset $blur $color;
}
/**
* Gives a card depth effect.
*
* @param {Number} $depth - depth level (between 1 and 5)
*
* @link https://www.google.com/design/spec/layout/layout-principles.html#layout-principles-dimensionality Google Design
*
* @requires {function} top-shadow
* @requires {function} bottom-shadow
*/
@mixin shadow($depth) {
@if $depth < 1 {
box-shadow: none;
} @else if $depth > 5 {
@warn "Invalid $depth `#{$depth}` for mixin `card`.";
} @else {
box-shadow: bottom-shadow($depth), top-shadow($depth);
}
}
/**\
| | Styles
\**/
.hand-wrapper {
@if ($debug) {
border: 1px solid red;
}
width: 100%;
position: absolute;
bottom: 5px;
.hand {
@if ($debug) {
border: 1px solid blue;
}
display: inline-block;
.card {
position: relative;
float: left;
//display: block;
background-color: #fff;
top: 0px;
width: $card-width;
height: $card-height;
@include shadow(1);
@include transform-style(preserve-3d);
@include transition(top 0.1s, box-shadow 0.2s);
&:hover {
@include shadow(2);
top: -20px;
}
&.flipped { // Doesnt work because of transforms
@include transform(rotateY(180deg));
}
.front, .back {
@include backface-visibility(hidden);
position: absolute;
width: 100%;
height: 100%;
}
.front {
@if ($debug) {
border: solid 1px green;
}
@include transform(rotateY(0deg));
}
.back {
@if ($debug) {
border: solid 1px orange;
}
@include transform(rotateY(180deg));
}
@for $i from 1 through $max-hand-size {
// i cards in hand
&:first-child:nth-last-child(#{$i}),
&:first-child:nth-last-child(#{$i}) ~ .card {
// hand fanning
$current-angle: floor($i/2)*$fanning-angle;
$current-gutter: floor($i/2)*$hand-gutter;
@for $j from 1 through $i {
&:nth-child(#{$j}) {
@include transform(rotate(#{$current-angle}));
left: $current-gutter;
}
$current-angle: $current-angle + -$fanning-angle;
$current-gutter: $current-gutter + -$hand-gutter;
}
}
}
}
}
}
// BUG: Dragging sometimes causes scroll bars to appear on the page.
//Happens when dragged element goes offscreen
body {
overflow: hidden;
margin: 0;
height: 100vh;
width: 100vw;
text-align: center;
}
* {
box-sizing: border-box;
}
//see https://www.greensock.com/draggable/ for more details.
var $hand = $('.hand');
var $cards = $(".card");
var myTarget = $(".play-trigger");
var overlapThreshold = "50%";
function onDrop(dragged, dropped) {
TweenMax.fromTo(dropped, 0.1, {opacity:1}, {opacity:0, repeat:3, yoyo:true});
console.log("dropped at x:" + this.x + " y:" + this.y);
}
Draggable.create($cards, {
zIndexBoost: false,
cursor: "pointer",
bounds: window,
onPress: function() {
console.log("drag started at x:" + this.x + " y:" + this.y);
},
onDragSStart: function() {
// <scale the card back down and instantiate drag physics>
},
onDrag: function(e) {
if (this.hitTest(myTarget, overlapThreshold)) {
myTarget.addClass("highlight");
} else {
myTarget.removeClass("highlight");
}
if (!this.hitTest($('.hand-wrapper'), overlapThreshold)) {
this.endDrag();
}
},
onRelease: function(e) {
//Not triggering mouseout and still counting
//as hovering if the mouse doesnt move after the drag ends.
if (this.hitTest(myTarget, overlapThreshold)) {
onDrop(this.target, myTarget);
}
console.log("released at x:" + this.x + " y:" + this.y);
TweenLite.to(this.target, 0.5, {x: 0, y: 0, ease: Expo.easeOut});
}
});
var hand = {
cards: $cards,
handSize: function() {
return $('.hand .card').length;
},
fanningConstant: -3,
fanningAngle: function(index) {
var angle = Math.floor(hand.handSize()/2)*this.fanningConstant;
return angle + this.fanningConstant*-index;
},
gutterConstant: 60,
gutterWidth: function(index) {
var gutter = Math.floor(hand.handSize()/2)*this.gutterConstant;
return gutter + this.gutterConstant*-index;
}
}
hand.cards.hover(function() {
TweenLite.to(this, 0, {rotation: 0, scale: 1.5, y: -20});
TweenLite.to(this, 3, {y: -30, ease: Expo.easeOut});
});
hand.cards.mouseout(function() {
var index = hand.cards.index(this);
TweenLite.to(this, 0.5, {rotation: hand.fanningAngle(index), y: 0});
TweenLite.to(this, 0, {scale: 1});
});
TweenMax.to(hand.cards.eq(0), 0, {rotationY: 180});
TweenLite.to(hand.cards.eq(3), 0, {rotationY: 180});
Also see: Tab Triggers