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 Skypack, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ES6 import
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="controls">
<a id="reset" href="#">Reset Rotation</a>
</div>
<div class="message">
<em>Click & drag left or right to rotate</em>
</div>
<div class="stage" id="stage">
<div class="positioning animated">
<div class="bmo">
<figure class="back">
<div class="slit"></div>
<div class="slit"></div>
<div class="slit"></div>
<div class="slit"></div>
<div class="slit"></div>
<div class="backpanel">
<span class="screw"></span>
<span class="screw"></span>
<span class="screw"></span>
<span class="screw"></span>
</div>
<div class="tapeslot"></div>
</figure>
<figure class="front">
<div class="face">
<span class="eye lefteye"></span>
<span class="eye righteye"></span>
<span class="smile"></span>
<div class="message1">
<h1>Back<br>in<br>5 Minutes</h1>
</div>
<div class="message2">
<img src="https://www.joshuawinn.com/wp-content/uploads/2015/07/dancing_bug.gif" alt="Dancing Bug" />
</div>
<div class="message3">
<img src="https://www.joshuawinn.com/wp-content/uploads/2015/07/bmo_skateboard.gif" alt="Dancing Bug" />
</div>
</div>
<div class="frontbuttons-flat">
<span class="slot"></span>
<span class="port leftport"></span>
<span class="port rightport"></span>
<span class="port tinyport"></span>
</div>
<div class="frontbuttons">
<div class="thedpad">
<div class="dpad">
<div class="square-top"></div><div class="square-top"></div>
<div class="square-top"></div><div class="square-top"></div>
<div class="square-top"></div>
</div>
<div class="dpad">
<div class="square-edge"></div><div class="square-edge"></div>
<div class="square-edge"></div><div class="square-edge"></div>
<div class="square-edge"></div><div class="square-edge"></div>
<div class="square-edge"></div><div class="square-edge"></div>
<div class="square-edge"></div><div class="square-edge"></div>
<div class="square-edge"></div><div class="square-edge"></div>
</div>
</div>
<div class="circlebig">
<div class="edges">
<div class="edge"></div><div class="edge"></div><div class="edge"></div><div class="edge"></div><div class="edge"></div><div class="edge"></div><div class="edge"></div><div class="edge"></div><div class="edge"></div><div class="edge"></div><div class="edge"></div><div class="edge"></div><div class="edge"></div><div class="edge"></div><div class="edge"></div><div class="edge"></div><div class="edge"></div><div class="edge"></div><div class="edge"></div><div class="edge"></div>
</div>
</div>
<div class="circlesmall">
<div class="edges">
<div class="edge"></div><div class="edge"></div><div class="edge"></div><div class="edge"></div><div class="edge"></div><div class="edge"></div><div class="edge"></div><div class="edge"></div><div class="edge"></div><div class="edge"></div><div class="edge"></div><div class="edge"></div><div class="edge"></div><div class="edge"></div><div class="edge"></div><div class="edge"></div>
</div>
</div>
<div class="triangle">
<div class="topleft"></div>
<div class="topright"></div>
</div>
</div>
</figure>
<figure class="left">
<div class="speaker">
<span></span><span></span><br/>
<span></span><span></span><span></span><br/>
<span></span><span></span>
</div>
<h1 class="label">BMO</h1>
<div class="arm"></div>
</figure>
<figure class="right">
<div class="speaker">
<span></span><span></span><br/>
<span></span><span></span><span></span><br/>
<span></span><span></span>
</div>
<h1 class="label">BMO</h1>
<div class="arm"></div>
</figure>
<figure class="top"></figure>
<figure class="bottom">
<div class="leg"></div>
<div class="leg left"></div>
</figure>
<!-- Rounded edges. For more explanation, see:
https://codepen.io/forthewinn/pen/OPpJpE -->
<div class="topleftcorner">
<div class="corner"></div><div class="corner"></div>
<div class="corner"></div><div class="corner"></div>
<div class="corner"></div><div class="corner"></div>
<div class="corner"></div><div class="corner"></div>
</div>
<div class="toprightcorner">
<div class="corner"></div><div class="corner"></div>
<div class="corner"></div><div class="corner"></div>
<div class="corner"></div><div class="corner"></div>
<div class="corner"></div><div class="corner"></div>
</div>
<div class="bottomleftcorner">
<div class="corner"></div><div class="corner"></div>
<div class="corner"></div><div class="corner"></div>
<div class="corner"></div><div class="corner"></div>
<div class="corner"></div><div class="corner"></div>
</div>
<div class="bottomrightcorner">
<div class="corner"></div><div class="corner"></div>
<div class="corner"></div><div class="corner"></div>
<div class="corner"></div><div class="corner"></div>
<div class="corner"></div><div class="corner"></div>
</div>
</div>
</div>
</div>
// Full blog post on subject:
// https://www.joshuawinn.com/bmo-3d-css-beemo-adventure-time/
@import "compass/css3";
// BEEMO Variables
$sizeHeight : 18.5em;
$sizeWidth : 14em;
$sizeDepth : 10em;
$sizeRounded : 0.9em;
$screencolor : #d7fae2;
// Font(s)
@import url('https://fonts.googleapis.com/css?family=Exo:700');
// ------------------------------------------------------------
// MATHEMATICAL!
// ROUND-THAT-EDGE
// A mixin for positioning of chamfered "faces" on the corner
// More info: https://codepen.io/forthewinn/pen/OPpJpE
// -- Makes use of Compass Math Helpers
// -- $angle-start = angle to start at (degrees).
// -- $faces = total faces. more = rounder. must match # of divs in HTML
// -- $totalangle = how far to round. "90deg" = edge. "360deg" = cylinder!
// -- $sizeround = width of half of circle (radius), in em/px
@mixin round-that-edge($faces:3, $angle-start:270, $totalangle: 90deg, $sizeround: $sizeRounded) {
// Make the edges a tiny bit wider, so there aren't gaps in the rendering
$gapfiller : 0.08em;
// angle that each face is turned within the 90 degrees
$angle : ($totalangle / $faces);
// half of that angle
$anglehalf : ($totalangle / $faces) / 2;
// CHORD length: distance between two points on circle = 2R*sin(C/2)
// http://www.mathopenref.com/chord.html
$sizeCorner : (2 * $sizeround) * sin($angle / 2);
// LOOP
// Generate CSS for each "face"/div that rounds the edge
$step-faces : 1;
@while $step-faces <= $faces {
// x and y on the circumference of a circle
// using cos and sin to find the endpoint of the chord on the circle.
//$x : $sizeround * cos($angle-start -($angle*$step-faces));
$x-oncircle : $sizeround * cos($angle-start - ($angle*$step-faces));
$y-oncircle : $sizeround * sin($angle-start - ($angle*$step-faces));
// our divs actually need to be positioned in the center of this point
// on the circle, and the previous point.
// previous point
$x-old : $sizeround * cos($angle-start - ($angle*($step-faces - 1)));
$y-old : $sizeround * sin($angle-start - ($angle*($step-faces - 1)));
// So we find the midpoint, by averaging old point & this point.
$x : ($x-oncircle + $x-old) / 2;
$y : ($y-oncircle + $y-old) / 2;
// save previous/starting points
$x-old : $x-oncircle;
$y-old : $y-oncircle;
// angle to rotate "faces"
$thisangle : ($angle * $step-faces) + $angle-start - $anglehalf;
// THE CSS
// Positions and rotates each additional div
&:nth-of-type(#{$step-faces}) {
height: $sizeCorner + $gapfiller;
@include transform(
translateX( $x )
translateY( $y + $sizeround - ($sizeCorner/2.0) - 0.05em )
rotateY( 90deg )
rotateX( $thisangle )
);
}
$step-faces: $step-faces + 1;
}
}
// ------------------------------------------------------------
/* RESET and border-box all the things */
*, *:before, *:after {
@include box-sizing(border-box);
margin:0; padding:0;
}
a { text-decoration:none; transition:all 0.35s ease; }
/* no text selection */
* { @include user-select(none); }
/* background/stage */
body {
// bg image by Tex-Tin-Star
// http://derekhunter.deviantart.com/art/adventure-time-background-258963973
background:#272627 url("https://www.joshuawinn.com/wp-content/uploads/2015/01/adventure_time_bg_image.jpg") no-repeat center center fixed;
background-size:cover;
font-family:sans-serif;
}
.stage {
position:relative;
margin:0 auto;
width:550px;
height:550px;
display:block;
@include perspective(1600px);
@include perspective-origin(50% -200px);
overflow:hidden; /* fixes scrollbar appearing in Firefox */
}
// EYES BLINKING ANIMATION ---------------------------
@include keyframes('eyeblink'){
96% {
margin-left:-0.25em;
border-radius:0; margin-top:0.2em;
height: 0.1em; width: 1.0em; background:#525252;
}
}
@include keyframes('eyeblinkright'){
96% {
margin-right:-0.25em;
border-radius:0; margin-top:0.2em;
height: 0.1em; width: 1.0em; background:#525252;
}
}
// BEEMO ---------------------------------------------
.bmo {
margin:0 auto;
width: $sizeWidth;
height: $sizeHeight;
position:relative;
text-align:center;
@include transform-style(preserve-3d);
&:hover { cursor:move; }
span { display:inline-block; }
/* All Sides */
figure {
background:#6fcaa7;
display: block;
position: absolute;
opacity: 1.0;
}
/* SIDES */
.front {
width: $sizeWidth;
height: $sizeHeight;
border-radius: $sizeRounded;
@include transform-style(preserve-3d);
@include transform(translateZ(5em));
border:2px solid #075636;
-webkit-backface-visibility: hidden;
backface-visibility: hidden;
}
.back {
width: $sizeWidth;
height: $sizeHeight;
border-radius: $sizeRounded;
background:#5cae98;
@include transform-style(preserve-3d);
@include transform(translateZ(-5em) rotateY(180deg));
border:2px solid #075636;
-webkit-backface-visibility:hidden;
backface-visibility:hidden;
}
.left {
height: $sizeHeight - ($sizeRounded * 2);
background:#67c7a7;
width: $sizeDepth;
@include transform-style(preserve-3d);
@include transform(
translateX(9.0em)
rotateY(90deg)
//translateZ($sizeDepth/2)
translateY($sizeRounded)
);
border-left:2px solid #075636;
border-right:2px solid #075636;
-webkit-backface-visibility:hidden;
backface-visibility:hidden;
}
.right {
height: $sizeHeight - ($sizeRounded * 2);
width: $sizeDepth;
background:#67c7a7;
@include transform-style(preserve-3d);
@include transform(
rotateY(-90deg)
translateZ($sizeDepth/2)
translateY($sizeRounded)
);
border-left:2px solid #075636;
border-right:2px solid #075636;
overflow:visible;
-webkit-backface-visibility:hidden;
backface-visibility:hidden;
}
.arm {
position:absolute;
left:50%;
bottom:-3.5em;
margin-left:-0.7em;
background:#63b3b2;
width:1.4em;
height:6.34em;
border-left:2px solid #0d4f41;
border-right:2px solid #0d4f41;
border-bottom:2px solid #0d4f41;
border-top:2px solid #031e33;
-webkit-backface-visibility:visible;
backface-visibility:visible;
transform-origin:50% 0;
border-radius:0 0 0.3em 0.3em;
@include transform(
rotateX(15deg)
);
&:after, &:before {
content:"";
position:absolute;
display:block;
width:2px;
height:0.7em;
background:#0d4f41;
}
&:after { left:25%; bottom:0; }
&:before { right:25%; bottom:0; }
}
.top {
height: $sizeDepth;
width: $sizeWidth - ($sizeRounded * 2);
background:#72ecc3;
@include transform(
rotateX(-90deg)
translateZ(-$sizeDepth/2)
translateX($sizeRounded)
);
border-top:2px solid #075636;
border-bottom:2px solid #075636;
}
.bottom {
@include transform-style(preserve-3d);
height: $sizeDepth;
width: $sizeWidth - ($sizeRounded * 2);
background:#75bea2;
@include transform(
translateY($sizeHeight - ($sizeDepth/2))
translateX($sizeRounded)
rotateX(-90deg)
);
border-top:2px solid #075636;
border-bottom:2px solid #075636;
-webkit-backface-visibility:hidden;
backface-visibility:hidden;
}
.leg {
position:absolute;
left:24%;
bottom:-3.0em;
background:#497e86;
width:1.3em;
margin-left:-0.65em;
height:7.6em;
border-left:1px solid #283926;
border-right:1px solid #283926;
-webkit-backface-visibility:visible;
backface-visibility:visible;
transform-origin:50% 0;
@include transform-style(preserve-3d);
@include transform( rotateX(90deg) );
&.left {
left:76%;
}
/* feet */
&:after {
content:"";
position:absolute;
display:block;
width:1.3em;
height:2.0em;
background:#497e86;
bottom:0;
left:0;
border-left:1px solid #283926;
border-right:1px solid #283926;
border-top:1px solid #283926;
border-radius:0.6em 0.6em 0 0;
transform-origin:50% 100%;
@include transform(
rotateX(-90deg)
);
}
}
/* Face */
/* ----------------------------*/
.face {
position:relative;
background:$screencolor;
border-radius:0.6em;
width:78%; height:8.5em;
margin:1.25em auto 1.0em auto;
border:2px solid #075636;
overflow:hidden;
.eye {
border-radius:100%;
width:0.5em;
height:0.5em;
position:absolute;
background:#000e00;
&.lefteye {
left:28%; top:35%;
@include animation(eyeblink 4.25s step-end -1s infinite);
}
&.righteye {
right:28%; top:35%;
@include animation(eyeblinkright 4.25s step-end -1s infinite);
}
}
.smile {
width:1.5em;
height:1.5em;
border-radius:100%;
border:1px solid #000e00;
position:absolute;
top:42%; left:50%; margin-left:-1em;
/* coverup partially with screen color */
&:after {
content:"";
display:block;
position:absolute;
top:50%; left:50%; margin-left:-0.75em;
margin-top:-0.75em;
width:2.25em;
height:1.0em;
background:$screencolor;
}
}
/* "Back in 5 minutes.." */
.message1, .message2, .message3 {
display:none;
position:absolute;
left:0; top:0;
width:100%; height:100%;
background:$screencolor;
}
.message1 {
h1 {
margin:0;
padding-top:1.35em;
text-align:center;
color:#13851f;
font-family:'Exo', sans-serif;
text-transform:uppercase;
font-size:20px;
line-height:1.25em;
}
}
.message2, .message3 {
overflow:hidden;
img {
display:block; margin:0;
position:absolute; left:0; top:0; width:100%;
}
}
.message3 img { width:auto; height:100%; }
}
/* All buttons and slots on the front */
/* ------------------------- */
.frontbuttons-flat {
position:relative;
margin:0 auto;
text-align:left;
width:75%;
.slot {
position:relative;
width:56%;
height:0.7em;
background:#1a534d;
box-shadow:inset 0 0 0.5em 0 rgba(0,0,0,0.8);
}
.port {
background:#1400b0;
box-shadow:inset 0 0 0.5em 0 rgba(0,0,0,0.8);
width:1.6em;
height:0.5em;
border-radius:0.4em;
position:absolute;
&.leftport { left:0; top:5.25em; }
&.rightport { left:2.1em; top:5.25em; }
&.tinyport {
width:0.7em;
height:0.7em;
border-radius:50%;
right:1.0em;
top:0.2em;
}
}
}
.frontbuttons {
position:absolute;
margin:0 auto;
text-align:left;
width:75%;
height:4.5em;
top:12.0em;
left:1.2em;
@include transform-style(preserve-3d);
-webkit-backface-visibility:hidden;
backface-visibility:hidden;
* {
-webkit-backface-visibility:hidden;
backface-visibility:hidden;
}
$dpad-square : 0.650em;
$button-depth : 0.5em;
$ds-half : ($button-depth) - ($dpad-square/2);
$dpad-highlight: #b9af29;
$fixgaps : 0.06em; // fixes some gaps appearing on dpad. not sure why.
.dpad {
position:absolute;
@include transform-style(preserve-3d);
left:2.0em;
top:0.6em;
.square-top {
transition:all 0.35s ease;
position:absolute;
background:#e8d22e;
width:$dpad-square + $fixgaps;
height:$dpad-square + $fixgaps;
transform-origin:50% 50%;
&:nth-child(2) { top:$dpad-square * 1; }
&:nth-child(3) { top:$dpad-square * 2; }
&:nth-child(4) { left:-$dpad-square * 1; top:$dpad-square * 1; }
&:nth-child(5) { left:$dpad-square * 1; top:$dpad-square * 1; }
/* pop out */
@include transform(
translateZ( $button-depth )
);
}
/* 3d depth to dpad, more rotated squares. */
.square-edge {
transition:all 0.35s ease;
position:absolute;
background:#a19821;
width:$dpad-square + $fixgaps;
height:$dpad-square + $fixgaps;
transform-origin:50% 50%;
/* top (ish) */
&:nth-child(1) {
@include transform(
translateX($dpad-square/2)
translateZ($ds-half)
rotateY(90deg)
);
}
&:nth-child(2) {
@include transform(
translateX(-$dpad-square/2)
translateZ($ds-half)
rotateY(270deg)
);
}
&:nth-child(3) {
background:$dpad-highlight;
@include transform(
translateX(-$dpad-square)
translateZ($ds-half)
translateY($dpad-square/2)
rotateY(90deg)
rotateX(90deg)
);
}
&:nth-child(4) {
background:$dpad-highlight;
@include transform(
translateX($dpad-square)
translateZ($ds-half)
translateY($dpad-square/2)
rotateY(90deg)
rotateX(90deg)
);
}
/* bottom (ish) */
&:nth-child(5) {
@include transform(
translateX($dpad-square/2)
translateZ($ds-half)
translateY($dpad-square*2)
rotateY(90deg)
);
}
&:nth-child(6) {
@include transform(
translateX(-$dpad-square/2)
translateZ($ds-half)
translateY($dpad-square*2)
rotateY(270deg)
);
}
&:nth-child(7) {
@include transform(
translateX(-$dpad-square)
translateZ($ds-half)
translateY($dpad-square/2 + ($dpad-square))
rotateY(90deg)
rotateX(90deg)
);
}
&:nth-child(8) {
@include transform(
translateX($dpad-square)
translateZ($ds-half)
translateY($dpad-square/2 + ($dpad-square))
rotateY(90deg)
rotateX(90deg)
);
}
/* end caps */
&:nth-child(9) {
background:$dpad-highlight;
@include transform(
translateZ($ds-half)
translateY(-$dpad-square/2)
rotateY(90deg)
rotateX(90deg)
);
}
&:nth-child(10) {
display:none; /* dont actually see bottom */
@include transform(
translateZ($ds-half)
translateY($dpad-square*2 + ($dpad-square/2))
rotateY(90deg)
rotateX(90deg)
);
}
&:nth-child(11) {
@include transform(
translateX( -$dpad-square - ($dpad-square/2))
translateZ($ds-half)
translateY($dpad-square)
rotateY(270deg)
);
}
&:nth-child(12) {
@include transform(
translateX($dpad-square + ($dpad-square/2))
translateZ($ds-half)
translateY($dpad-square)
rotateY(90deg)
);
}
}
}
.thedpad:hover {
.dpad {
.square-top { background:#fffab8; }
.square-edge { background:#dad378; }
}
}
/* pressable */
.dpad, .redbutton, .greenbutton, .bluebutton, .circlebig, .circlesmall {
cursor:pointer;
}
/* CIRCLE BUTTONS */
.circlebig {
position:absolute;
@include transform-style(preserve-3d);
right:1.5em;
top:2.6em;
background:#e9004f;
width:1.8em;
height:1.8em;
border-radius:100%;
/* pop out */
@include transform( translateZ( $button-depth ) );
.edges {
position:absolute;
width:100%;
height:100%;
display: block;
@include transform-style(preserve-3d);
left:0.6em;
top:0;
@include transform( translateZ( -$button-depth/2 + 0.06em ) );
}
.edge {
// Use Mixin to generate beveled edges, to create cylinder. woot.
@include round-that-edge(20, 0, 360deg, 0.9em);
background:#890335;
width: $button-depth;
position:absolute;
transform-origin:50% 50%;
}
&:hover {
background:#f3447f;
.edge { background:#d61c60; }
}
}
.circlesmall {
position:absolute;
@include transform-style(preserve-3d);
right:0.3em;
top:1.7em;
background:#15d326;
width:1.0em;
height:1.0em;
border-radius:100%;
/* pop out */
@include transform( translateZ( $button-depth ) );
.edges {
position:absolute;
width:100%;
height:100%;
display: block;
@include transform-style(preserve-3d);
left:0.25em;
top:0;
@include transform( translateZ( -$button-depth/2 + 0.04em ) );
}
.edge {
// Use Mixin to generate beveled edges, to create cylinder. woot.
@include round-that-edge(16, 0, 360deg, 0.5em);
background:#10791b;
width: $button-depth;
position:absolute;
transform-origin:50% 50%;
}
&:hover {
background:#11f125;
.edge { background:#1abb2b; }
}
}
// TRIANGLE BUTTON
.triangle {
position:absolute;
@include transform-style(preserve-3d);
right:2.5em;
top:0.6em;
width:1.4em;
height: 0;
border-left: 0.85em solid transparent;
border-right: 0.85em solid transparent;
border-bottom: 1.4em solid #15dad1;
/* pop out */
@include transform( translateZ( $button-depth ) );
/* depth polys */
.topleft, .topright {
width:$button-depth;
height:1.42em;
position:absolute;
top:100%;
border-top:1px solid #11b3ac;
background:#228c9a;
transform-origin:50% 50%;
@include transform-style(preserve-3d);
}
.topleft {
left:-0.62em;
@include transform(
translateZ(-$button-depth/2)
rotateY(270deg)
rotateX(34.56deg)
);
}
.topright {
right:-0.62em;
@include transform(
translateZ(-$button-depth/2)
rotateY(90deg)
rotateX(34.56deg)
);
}
}
} // end .frontbuttons
/* BMO text on the side */
/* ------------------------- */
.label {
font-size:3.8em;
padding-top: 0.075em;
color:#031e33;
font-weight:700;
font-family:'Exo', sans-serif;
letter-spacing:0.1em;
text-shadow:
-1px -1px 0 #000211,
1px -1px 0 #000211,
-1px 1px 0 #000211,
1px 1px 0 #000211;
/*
-webkit-backface-visibility: hidden;
backface-visibility: hidden;
*/
text-align:center;
@include transform(rotateZ(90deg));
position:relative;
top:22%;
}
/* Speaker dots */
.speaker {
text-align:center;
margin-top:1.0em;
line-height:22px;
span {
border-radius:100%;
width:0.4em;
height:0.4em;
background:#000e00;
margin:0 6%;
}
}
/* Back stuff */
/* ------------------------- */
.slit {
width:0.5em;
height:4em;
display:inline-block;
margin:1.5em 5% 2.0em 5%;
border-radius:0.2em;
border:1px solid #022d1d;
background:#1a534d;
box-shadow:inset 0 0 0.5em 0 rgba(0,0,0,0.8);
}
.backpanel,
.tapeslot {
position:relative;
margin:0 auto;
width:70%;
border:1px solid #022d1d;
}
.backpanel {
height:6.5em;
margin-bottom:1.0em;
border-radius:0.25em;
@include transform-style(preserve-3d);
.screw {
width:0.3em;
height:0.3em;
border-radius:50%;
background:#123f28;
border:1px solid #022d1d;
position:absolute;
&:nth-child(1){ left:0.25em; top:0.25em; }
&:nth-child(2){ left:0.25em; bottom:0.25em; }
&:nth-child(3){ right:0.25em; top:0.25em; }
&:nth-child(4){ right:0.25em; bottom:0.25em; }
}
}
.tapeslot {
height:1.6em;
margin:0 auto;
width:50%;
border:1px solid #022d1d;
}
/* skinny rotated elements used to round corners */
.corner {
width: $sizeDepth;
position:absolute;
transform-origin:50% 50%;
background:#67c7a7;
border-left:2px solid #075636;
border-right:2px solid #075636;
}
/* Beveled Edges */
/* ------------------------- */
.toprightcorner,
.topleftcorner,
.bottomleftcorner,
.bottomrightcorner {
position:absolute;
display: block;
@include transform-style(preserve-3d);
}
.topleftcorner {
@include transform(
translateX( -4.08em )
);
}
.toprightcorner {
@include transform(
translateX( 8.08em )
);
}
.bottomrightcorner {
@include transform(
translateX( -4.08em )
translateY( $sizeHeight - ($sizeRounded*2) )
);
}
.bottomleftcorner {
@include transform(
translateX( 8.08em )
translateY( $sizeHeight - ($sizeRounded*2) )
);
}
// Mixin to generate beveled edges
.topleftcorner .corner {
@include round-that-edge(8, 270);
}
.toprightcorner .corner {
@include round-that-edge(8, 0);
}
.bottomleftcorner .corner {
@include round-that-edge(8, 90);
}
.bottomrightcorner .corner {
@include round-that-edge(8, 180);
}
}
// ANIMATION AND CONTROLS -----------------------------------
.positioning {
position: absolute;
width: 16em;
top: 4em;
left: 50%;
margin-left: -8em;
@include transform-style(preserve-3d);
//@include transform(rotateY(-80deg) rotateX(-80deg));
}
.positioning.animated {
//@include animation(fullRotate 8s linear infinite);
}
/* Rotate 360 degrees */
@include keyframes(fullRotate) {
from { @include transform(rotateY(0deg)); }
to { @include transform(rotateY(360deg)); }
}
.controls {
z-index:100;
text-align:right;
position:absolute;
right:8px; top:8px;
font-size:12px;
letter-spacing:1px;
text-transform:uppercase;
a {
color:#d5d5d5;
border-bottom:1px dotted #666666;
&:hover {
color:#72ecc3;
border-bottom:1px dotted #316755;
}
}
}
.message {
position:absolute;
top:24px;
width:100%;
text-align:center;
color:#ffffff;
text-transform:uppercase;
font-size:12px;
text-shadow:1px 1px 8px rgba(0,0,0,0.75);
}
// Traqball.js for rotating around stage with mouse
var thestage;
window.addEventListener("load", callback, false);
function callback(){
thestage = new Traqball({
stage: "stage",
axis: [0,0.777,0],
angle: 0.5,
limitAxxis: "y"
});
}
// Global Controls
// Reset to starting rotation
$('#reset').click(function(e){
e.preventDefault();
thestage.setup({ axis: [0,0.777,0] });
});
// FUN BUTTONS
$('.dpad').on('click', function(e){
e.preventDefault();
// show, or hide if visible
$(".face .message1").toggle();
$(".message2, .message3").hide();
// auto hide after a few secs
setTimeout(function(){$(".face .message1").hide();}, 5000);
});
$('.circlebig').on('click', function(e){
e.preventDefault();
// show, or hide if visible
$(".message1, .message3").hide();
$(".message2").toggle();
});
$('.circlesmall').on('click', function(e){
e.preventDefault();
// show, or hide if visible
$(".message1, .message2").hide();
$(".message3").toggle();
});
/*
* traqball 2.2
* written by Dirk Weber
* http://www.eleqtriq.com/
* See demo at: http://www.eleqtriq.com/wp-content/static/demos/2011/traqball2011
* Copyright (c) 2011 Dirk Weber (http://www.eleqtriq.com)
* Licensed under the MIT (http://www.eleqtriq.com/wp-content/uploads/2010/11/mit-license.txt)
*/
(function(){
var userAgent = navigator.userAgent.toLowerCase(),
canTouch = "ontouchstart" in window,
cssPref = "",
prefix = "",
requestAnimFrame, cancelAnimFrame;
if(/webkit/gi.test(userAgent)){
prefix = "-webkit-";
cssPref = "Webkit";
}else if(/msie | trident/gi.test(userAgent)){
prefix = "-ms-";
cssPref = "ms";
}else if(/mozilla/gi.test(userAgent)){
prefix = "-moz-";
cssPref = "Moz";
}else if(/opera/gi.test(userAgent)){
prefix = "-o-";
cssPref = "O";
}else{
prefix = "";
}
function bindEvent(target, type, callback, remove){
//translate events
var evType = type || "touchend",
mouseEvs = ["mousedown", "mouseup", "mousemove"],
touchEvs = ["touchstart", "touchend", "touchmove"],
remove = remove || "add";
evType = canTouch ? evType : mouseEvs[touchEvs.indexOf(type)];
target[remove+"EventListener"](evType, callback, false);
}
function getCoords(eventObj){
var xTouch,
yTouch;
if(eventObj.type.indexOf("mouse") > -1){
xTouch = eventObj.pageX;
yTouch = eventObj.pageY;
}else if(eventObj.type.indexOf("touch") > -1){
//only do stuff if 1 single finger is used:
if(eventObj.touches.length === 1){
var touch = eventObj.touches[0];
xTouch = touch.pageX;
yTouch = touch.pageY;
}
}
return [xTouch, yTouch];
}
function getStyle(target, prop){
var style = document.defaultView.getComputedStyle(target, "");
return style.getPropertyValue(prop);
}
requestAnimFrame = (function(){
return window[cssPref+"RequestAnimationFrame"] ||
function(callback){
window.setTimeout(callback, 17);
};
})();
cancelAnimFrame = (function(){
return window[cssPref+"CancelRequestAnimationFrame"] ||
clearTimeout;
})();
var Traqball = function(confObj){
this.config = {};
this.box = null;
this.setup(confObj);
};
Traqball.prototype.disable = function(){
if(this.box !== null){
bindEvent(this.box, 'touchstart', this.evHandlers[0], "remove");
bindEvent(document, 'touchmove', this.evHandlers[1], "remove");
bindEvent(document, 'touchend', this.evHandlers[2], "remove");
}
}
Traqball.prototype.activate = function(){
if(this.box !== null){
bindEvent(this.box, 'touchstart', this.evHandlers[0]);
bindEvent(document, 'touchmove', this.evHandlers[1], "remove");
bindEvent(document, 'touchend', this.evHandlers[2], "remove");
}
}
Traqball.prototype.setup = function(conf){
var THIS = this,
radius, // prepare a variable for storing the radius of our virtual trackball
stage, // the DOM-container of our "rotatable" element
axis = [], // The rotation-axis
mouseDownVect = [], // Vector on mousedown
mouseMoveVect = [], // Vector during mousemove
stopMatrix = [],
startMatrix = [], // Transformation-matrix at the moment of *starting* dragging
delta = 0,
impulse, pos, w, h, decr, angle, oldAngle, oldTime, curTime;
(function init (){
THIS.disable();
for(var prop in conf){
THIS.config[prop] = conf[prop];
}
stage = document.getElementById(THIS.config.stage) || document.getElementsByTagname("body")[0];
pos = findPos(stage);
angle = THIS.config.angle || 0;
impulse = THIS.config.impulse === false ? false : true;
// Let's calculate some basic values from "stage" that are necessary for our virtual trackball
// 1st: determine the radius of our virtual trackball:
h = stage.offsetHeight/2,
w = stage.offsetWidth/2;
//take the shortest of both values as radius
radius = h<w ? h : w;
//We parse viewport. The first block-element we find will be our "victim" and made rotatable
for(var i=0, l=stage.childNodes.length; i<l; i++){
var child = stage.childNodes[i];
if(child.nodeType === 1){
THIS.box = child;
break;
}
}
var perspective = getStyle(stage, prefix+"perspective"),
pOrigin = getStyle(stage, prefix+"perspective-origin"),
bTransform = getStyle(THIS.box, prefix+"transform");
//Let's define the start values. If "conf" contains angle or perspective or vector, use them.
//If not, look for css3d transforms within the CSS.
//If this fails, let's use some default values.
if(THIS.config.axis || THIS.config.angle){
// Normalize the initAxis (initAxis = axis of rotation) because "box" will look distorted if normal is too long
axis = normalize(THIS.config.axis) || [1,0,0];
angle = THIS.config.angle || 0;
// Last but not least we calculate a matrix from the axis and the angle.
// This matrix will store the initial orientation in 3d-space
startMatrix = calcMatrix(axis, angle);
}else if(bTransform !== "none"){
//already css3d transforms on element?
startMatrix = bTransform.split(",");
//Under certain circumstances some browsers report 2d Transforms.
//Translate them to 3d:
if(/matrix3d/gi.test(startMatrix[0])){
startMatrix[0] = startMatrix[0].replace(/(matrix3d\()/g, "");
startMatrix[15] = startMatrix[15].replace(/\)/g, "");
}else{
startMatrix[0] = startMatrix[0].replace(/(matrix\()/g, "");
startMatrix[5] = startMatrix[5].replace(/\)/g, "");
startMatrix.splice(2,0,0,0);
startMatrix.splice(6,0,0,0);
startMatrix.splice(8,0,0,0,1,0);
startMatrix.splice(14,0,0,1);
}
for(var i = 0, l = startMatrix.length; i<l; i++){
startMatrix[i] = parseFloat(startMatrix[i]);
}
}else{
axis = [0,1,0];
angle = 0;
startMatrix = calcMatrix(axis, angle);
}
if(THIS.config.perspective){
stage.style[cssPref+"Perspective"] = THIS.config.perspective;
}else if(perspective === "none"){
stage.style[cssPref+"Perspective"] = "700px";
}
if(THIS.config.perspectiveOrigin){
stage.style[cssPref+"PerspectiveOrigin"] = THIS.config.perspectiveOrigin;
}
THIS.box.style[cssPref+"Transform"] = "matrix3d("+ startMatrix+")";
bindEvent(THIS.box, 'touchstart', startrotation);
THIS.evHandlers = [startrotation, rotate, finishrotation];
})();
function startrotation(e){
if(delta !== 0){stopSlide();};
e.preventDefault();
mouseDownVect = calcZvector(getCoords(e));
oldTime = curTime = new Date().getTime();
oldAngle = angle;
bindEvent(THIS.box,'touchstart', startrotation, "remove");
bindEvent(document, 'touchmove', rotate);
bindEvent(document, 'touchend', finishrotation);
}
function finishrotation(e){
//var stopMatrix;
bindEvent(document, 'touchmove', rotate, "remove");
bindEvent(document, 'touchend', finishrotation, "remove");
bindEvent(THIS.box, 'touchstart', startrotation);
calcSpeed();
if( impulse && delta > 0){
requestAnimFrame(slide);
}else if(!(isNaN(axis[0]) || isNaN(axis[1]) || isNaN(axis[2]))) {
stopSlide();
}
}
function cleanupMatrix(){
// Clean up when finishing rotation. Only thing to do: create a new "initial" matrix for the next rotation.
// If we don't, the object will flip back to the position at launch every time the user starts dragging.
// Therefore we must:
// 1. calculate a matrix from axis and the current angle
// 2. Create a new startmatrix by combining current startmatrix and stopmatrix to a new matrix.
// Matrices can be combined by multiplication, so what are we waiting for?
stopMatrix = calcMatrix(axis, angle);
startMatrix = multiplyMatrix(startMatrix,stopMatrix);
}
// The rotation:
function rotate(e){
var eCoords = getCoords(e);
e.preventDefault();
oldTime = curTime;
oldAngle = angle;
// Calculate the currrent z-component of the 3d-vector on the virtual trackball
mouseMoveVect = calcZvector(eCoords);
// We already calculated the z-vector-component on mousedown and the z-vector-component during mouse-movement.
// We will use them to retrieve the current rotation-axis
// (the normal-vector perpendiular to mouseDownVect and mouseMoveVect).
axis[0] = mouseDownVect[1]*mouseMoveVect[2]-mouseDownVect[2]*mouseMoveVect[1];
axis[1] = mouseDownVect[2]*mouseMoveVect[0]-mouseDownVect[0]*mouseMoveVect[2];
axis[2] = mouseDownVect[0]*mouseMoveVect[1]-mouseDownVect[1]*mouseMoveVect[0];
axis = normalize(axis);
// Now that we have the normal, we need the angle of the rotation.
// Easy to find by calculating the angle between mouseDownVect and mouseMoveVect:
angle = calcAngle(mouseDownVect, mouseMoveVect);
//Only one thing left to do: Update the position of the box by applying a new transform:
// 2 transforms will be applied: the current rotation 3d and the start-matrix
THIS.box.style[cssPref+"Transform"] = "rotate3d("+ axis+","+angle+"rad) matrix3d("+startMatrix+")";
curTime = new Date().getTime();
}
function calcSpeed(){
var dw = angle - oldAngle;
var dt = curTime-oldTime;
delta = Math.abs(dw*17/dt);
if(isNaN(delta)){
delta = 0;
}else if(delta > 0.2){
delta = 0.2;
}
}
function slide(){
angle+= delta;
decr = 0.01*Math.sqrt(delta);
delta = delta > 0 ? delta-decr : 0;
THIS.box.style[cssPref+"Transform"] = "rotate3d("+ axis+","+angle+"rad) matrix3d("+startMatrix+")";
if (delta === 0){
stopSlide();
}else{
requestAnimFrame(slide);
}
}
function stopSlide(){
cancelAnimFrame(slide);
cleanupMatrix();
oldAngle = angle = 0;
delta = 0;
}
//Some stupid matrix-multiplication.
function multiplyMatrix(m1, m2){
var matrix = [];
matrix[0] = m1[0]*m2[0]+m1[1]*m2[4]+m1[2]*m2[8]+m1[3]*m2[12];
matrix[1] = m1[0]*m2[1]+m1[1]*m2[5]+m1[2]*m2[9]+m1[3]*m2[13];
matrix[2] = m1[0]*m2[2]+m1[1]*m2[6]+m1[2]*m2[10]+m1[3]*m2[14];
matrix[3] = m1[0]*m2[3]+m1[1]*m2[7]+m1[2]*m2[11]+m1[3]*m2[15];
matrix[4] = m1[4]*m2[0]+m1[5]*m2[4]+m1[6]*m2[8]+m1[7]*m2[12];
matrix[5] = m1[4]*m2[1]+m1[5]*m2[5]+m1[6]*m2[9]+m1[7]*m2[13];
matrix[6] = m1[4]*m2[2]+m1[5]*m2[6]+m1[6]*m2[10]+m1[7]*m2[14];
matrix[7] = m1[4]*m2[3]+m1[5]*m2[7]+m1[6]*m2[11]+m1[7]*m2[15];
matrix[8] = m1[8]*m2[0]+m1[9]*m2[4]+m1[10]*m2[8]+m1[11]*m2[12];
matrix[9] = m1[8]*m2[1]+m1[9]*m2[5]+m1[10]*m2[9]+m1[11]*m2[13];
matrix[10] = m1[8]*m2[2]+m1[9]*m2[6]+m1[10]*m2[10]+m1[11]*m2[14];
matrix[11] = m1[8]*m2[3]+m1[9]*m2[7]+m1[10]*m2[11]+m1[11]*m2[15];
matrix[12] = m1[12]*m2[0]+m1[13]*m2[4]+m1[14]*m2[8]+m1[15]*m2[12];
matrix[13] = m1[12]*m2[1]+m1[13]*m2[5]+m1[14]*m2[9]+m1[15]*m2[13];
matrix[14] = m1[12]*m2[2]+m1[13]*m2[6]+m1[14]*m2[10]+m1[15]*m2[14];
matrix[15] = m1[12]*m2[3]+m1[13]*m2[7]+m1[14]*m2[11]+m1[15]*m2[15];
return matrix;
}
// This function will calculate a z-component for our 3D-vector from the mouse x and y-coordinates
// (the corresponding point on our virtual trackball):
function calcZvector(coords){
var x = THIS.config.limitAxxis === "x" ? radius : coords[0] - pos[0],
y = THIS.config.limitAxxis === "y" ? radius : coords[1] - pos[1],
vector = [(x/radius-1), (y/radius-1)],
z = 1 - vector[0]*vector[0] - vector[1]*vector[1];
// Make sure that dragging stops when z gets a negative value:
vector[2] = z > 0 ? Math.sqrt(z) : 0;
return vector;
}
// Normalization recalculates all coordinates in a way that the resulting vector has a length of "1".
// We achieve this by dividing the x, y and z-coordinates by the vector's length
function normalize(vect){
var length = Math.sqrt( vect[0]*vect[0] + vect[1]*vect[1] + vect[2]*vect[2] );
vect[0]/= length;
vect[1]/= length;
vect[2]/= length;
return vect;
}
// Calculate the angle between 2 vectors.
function calcAngle(vect_1, vect_2){
var numerator = vect_1[0]*vect_2[0] + vect_1[1]*vect_2[1] + vect_1[2]*vect_2[2],
denominator = Math.sqrt(vect_1[0]*vect_1[0] + vect_1[1]*vect_1[1] + vect_1[2]*vect_1[2])*
Math.sqrt(vect_2[0]*vect_2[0] + vect_2[1]*vect_2[1] + vect_2[2]*vect_2[2]),
angle = Math.acos(numerator/denominator);
return angle;
}
function calcMatrix(vector, angle){
// calculate transformation-matrix from a vector[x,y,z] and an angle
var x = vector[0],
y = vector[1],
z = vector[2],
sin = Math.sin(angle),
cos = Math.cos(angle),
cosmin = 1-cos,
matrix = [(cos+x*x*cosmin), (y*x*cosmin+z*sin),(z*x*cosmin-y*sin),0,
(x*y*cosmin-z*sin), (cos+y*y*cosmin), (z*y*cosmin+x*sin),0,
(x*z*cosmin+y*sin), (y*z*cosmin-x*sin), (cos+z*z*cosmin),0,
0,0,0,1];
return matrix;
}
//findPos-script by www.quirksmode.org
function findPos(obj) {
var curleft = 0,
curtop = 0;
if (obj.offsetParent) {
do {
curleft += obj.offsetLeft;
curtop += obj.offsetTop;
} while (obj = obj.offsetParent);
return [curleft,curtop];
}
}
}
window.Traqball = Traqball;
})();
// Make message go away.
$('#stage').on('click', function(){
$(".message > em")
.text('Algebraic!')
.delay(200)
.fadeOut(1500);
});
// Special functions
$('.dpad, .redbutton, .greenbutton, .bluebutton').click(function(){
$(".message > em").hide();
});
Also see: Tab Triggers