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 id="cvs">
    <div id="cube">
        
        <div class="cubeface top">
            <div class="square"></div>
            <div class="square"></div>
            <div class="square"></div>
            <div class="square"></div>
        </div>
        <div class="cubeface front">
            <div class="square"></div>
            <div class="square"></div>
            <div class="square"></div>
            <div class="square"></div>
            <div class="square"></div>
        </div>
        <div class="cubeface right">
            <div class="square"></div>
            <div class="square"></div>
            <div class="square"></div>
            <div class="square"></div>
            <div class="square"></div>
            <div class="square"></div>
        </div>
        <div class="cubeface back"></div>
        <div class="cubeface left"></div>
        <div class="cubeface bottom"></div>
        
        <div id="minicube">
            <div class="minicubeface top"></div>
            <div class="minicubeface front"></div>
            <div class="minicubeface left"></div>
            <div class="minicubeface right"></div>
            <div class="minicubeface back"></div>
            <div class="minicubeface bottom"></div>
        </div>
    
    </div>
    
</div>
              
            
!

CSS

              
                $cubesize: 150px;
$cSize: $cubesize / 3;
$delay: .06s;

html, body {
    margin: 0;
    height: 100%;
    background: black;
    overflow: hidden;
}

@-webkit-keyframes cubeshake {
    0% { transform: translate3d(-$cubesize/2,-$cubesize,0) rotateX(55deg) rotateZ(45deg); }
    50% { transform: translate3d(-$cubesize/2,-$cubesize,0) rotateX(45deg) rotateZ(45deg); top:55%; }
    100% { transform: translate3d(-$cubesize/2,-$cubesize,0) rotateX(55deg) rotateZ(45deg); }
}
@-webkit-keyframes cubeshakeStart {
    0% { transform: translate3d(-$cubesize/2,-$cubesize,0) rotateX(55deg) rotateZ(45deg); }
    50% { transform: translate3d(-$cubesize/2,-$cubesize,0) rotateX(55deg) rotateY(10deg) rotateZ(45deg); top:55%; }
    100% { transform: translate3d(-$cubesize/2,-$cubesize,0) rotateX(55deg) rotateZ(45deg); }
}

@-webkit-keyframes cubeglow {
    0% { box-shadow: none; }
    50% { box-shadow: inset 0 0 $cSize 5px rgba(255,255,255,.3); }
    100% { box-shadow: none; }
}
@-webkit-keyframes cubeglowStart {
    0% { box-shadow: none; }
    50% { box-shadow: inset 0 0 $cSize 5px rgba(255,255,255,.3); }
    100% { box-shadow: none; }
}

@-webkit-keyframes fall {
    0% { transform: translate3d($cSize*2, 0, $cSize*10); }
    100% { transform: translate3d($cSize*2, 0, 0); }
}
@-webkit-keyframes jump {
    0% { transform: translate3d($cubesize, $cSize, -$cSize) rotateX(0deg) rotateY(0deg) rotateZ(0deg); }
    75% { transform: translate3d($cSize*1.5, $cSize*1.5, $cSize) rotateX(0deg) rotateY(180deg) rotateZ(0deg); }
    100% { transform: translate3d($cSize*1.5, $cSize*1.5, -$cSize*1.5) rotateX(0deg) rotateY(180deg) rotateZ(0deg); }
}

#cvs {
    width: 100%;
    height: 100%;
    perspective: 999999999px;
}

#cube {
    position: absolute;
    height: $cubesize;
    width: $cubesize;
    left: 50%;
    top: 50%;
    transform-style: preserve-3d;
    transform: translate3d(-$cubesize/2,-$cubesize,0) rotateX(55deg) rotateZ(45deg);
    -webkit-animation: cubeshakeStart $delay*5 ease-out;
    -webkit-animation-delay: $delay*4;
}
#cube.full {
    -webkit-animation: cubeshake $delay*5 ease-out;
    -webkit-animation-delay: $delay*7;
}
#cube.shake {
    -webkit-animation: cubeshake $delay*5;
}

.cubeface {
    position: absolute;
    height: $cubesize;
    width: $cubesize;
    transform-style: preserve-3d;
    -webkit-animation: cubeglowStart $delay*5 ease-out;
    -webkit-animation-delay: $delay*4;
}
#cube.full .cubeface {
    -webkit-animation: cubeglow $delay*5 ease-out;
    -webkit-animation-delay: $delay*7;
}

.cubeface.front {
    top: $cubesize;
    transform-origin: top;
    transform: rotateX(-90deg);
}
.cubeface.back {
    transform-origin: top;
    transform: rotateX(-90deg);
}
.cubeface.right {
    left: $cubesize;
    transform-origin: left;
    transform: rotateY(90deg);
}
.cubeface.left {
    transform-origin: left;
    transform: rotateY(90deg);
}
.cubeface.bottom {
    transform: translateZ(-$cubesize);
}

.square {
    opacity: 0;
    position: absolute;
    height: $cSize;
    width: $cSize;
    background: #5e4cba;
    border: ceil($cSize/20) solid black;
    box-sizing: border-box;
    transition: all $delay*3, opacity $delay;
}
.square.visible {
    opacity: 1;
}

#cube.metal .square {
    border: 0;
}
#cube.metal .top .square {
    background: #e2e6e9;
}
#cube.metal .front .square {
    background: #898fbf;
}
#cube.metal .right .square {
    background: #535e8b;
}

.top .square:nth-child(1) { top:0; left:$cSize; }
.top .square:nth-child(2) { top:0; left:0; }
.top .square:nth-child(3) { top:$cSize; left:0; }
.top .square:nth-child(4) { top:$cSize*2; left:0; }

.front .square:nth-child(1) { top:0; left:0; }
.front .square:nth-child(2) { top:$cSize; left:0; }
.front .square:nth-child(3) { top:$cSize*2; left:0; }
.front .square:nth-child(4) { top:$cSize*2; left:$cSize; }
.front .square:nth-child(5) { top:$cSize*2; left:$cSize*2; }

.right .square:nth-child(1) { top:$cSize*2; left:$cSize*2; }
.right .square:nth-child(2) { top:$cSize; left:$cSize*2; }
.right .square:nth-child(3) { top:0; left:$cSize*2; }
.right .square:nth-child(4) { top:0; left:$cSize; }
.right .square:nth-child(5) { top:0; left:0; }
.right .square:nth-child(6) { top:$cSize; left:0; }

#minicube {
    position: absolute;
    width: $cSize;
    height: $cSize;
    transform: translate3d($cSize*2, 0, 0);
    transform-style: preserve-3d;
    transform-origin: 0 0 0;
    -webkit-animation: fall $delay*5 ease-in;
}
#minicube.transition {
    transition: all $delay;
}

.minicubeface {
    position: absolute;
    width: $cSize;
    height: $cSize;
    background: radial-gradient(#5e4cba, #7059e5) center;
    background-size: $cSize*2 $cSize*2;
    border: 1px solid #4f3fa1;
    transform-style: preserve-3d;
    box-sizing: border-box;
    transition: all $delay*8 ease-in, background $delay;
}
.minicubeface.top {
    transform: translate3d(0, 0, $cSize);
}
.minicubeface.front {
    transform-origin: bottom;
    transform: rotateX(-90deg);
}
.minicubeface.left {
    transform-origin: left;
    transform: rotateY(-90deg);
}
.minicubeface.right {
    transform-origin: right;
    transform: rotateY(90deg);
}
.minicubeface.back {
    transform-origin: top;
    transform: rotateX(90deg);
}

#minicube.grow {
    -webkit-animation: jump $delay*8 cubic-bezier(.5,1.2,0,.9);
    transform: translate3d($cSize*1.5, $cSize*1.5, -$cSize*1.5) rotateY(180deg) !important;
    transform-origin: 75% 75% $cSize*.75 !important;
}
#minicube.grow .minicubeface {
    width: $cSize * 1.5;
    height: $cSize * 1.5;
}
#minicube.grow .minicubeface.top {
    transform: translate3d(0, 0, $cSize * 1.5);
}


#cube.metal .minicubeface {
    border: 0;
}
#cube.metal .minicubeface.bottom {
    background: #e2e6e9;
}
#cube.metal .minicubeface.front {
    background: #898fbf;
}
#cube.metal .minicubeface.left {
    background: #535e8b;
}
              
            
!

JS

              
                var c = $('#minicube');
var cubeSize = 150;
var cSize = cubeSize / 3;

var x = cSize * 2;
var y = 0;
var z = 0;
var delay = 60;

function metal() {
    if($('.square').length == $('.square.visible').length) {
        $('#cube').addClass('full');
        setTimeout(function() {
            $('#cube').addClass('metal');
        }, delay * 8);
    }
}

function rX(d) {
    c.toggleClass('transition').css('transform', 'translate3d('+x+'px, '+y+'px, '+z+'px) rotateX('+d+'deg)');
}
function rY(d) {
    c.toggleClass('transition').css('transform', 'translate3d('+x+'px, '+y+'px, '+z+'px) rotateY('+d+'deg)');
}
function rZ(d) {
    c.toggleClass('transition').css('transform', 'translate3d('+x+'px, '+y+'px, '+z+'px) rotateZ('+d+'deg)');
}

function animate() {
    
    var i = 0;
    
    $('.cubeface .square').each(function(key, value) {
        var sq = $(this);
        setTimeout(function() {
            sq.addClass('visible');
            metal();
        }, delay * 2 * (key+1));
    });
    
    // moving left
    setTimeout(function() { rY(-90); }, delay*(i++));
    setTimeout(function() { x -= cSize; rY(0); }, delay*(i++));
    setTimeout(function() { rY(-90); }, delay*(i++));
    // switch
    setTimeout(function() { 
        x -= cSize; 
        rY(0);
        c.css('transform-origin', cSize+'px '+cSize+'px 0');
    }, delay*(i++));
    // moving forward
    setTimeout(function() { rX(-90); }, delay*(i++));
    setTimeout(function() { y += cSize; rX(0); }, delay*(i++));
    setTimeout(function() { rX(-90); }, delay*(i++));
    setTimeout(function() { y += cSize; rX(0); }, delay*(i++));
    setTimeout(function() { rX(-180); }, delay*(i++));
    //switch
    setTimeout(function() { 
        y += cSize;
        z -= cSize;
        rX(0);
        c.css('transform-origin', cSize+'px 0 0');
    }, delay*(i++));
    // moving down
    setTimeout(function() { rX(-90); }, delay*(i++));
    setTimeout(function() { z -= cSize; rX(0); }, delay*(i++));
    setTimeout(function() { rX(-90); }, delay*(i++));
    //switch
    setTimeout(function() { 
        z -= cSize;
        rX(0);
    }, delay*(i++));
    // moving right
    setTimeout(function() { rZ(-90); }, delay*(i++));
    setTimeout(function() { x += cSize; rZ(0); }, delay*(i++));
    setTimeout(function() { rZ(-90); }, delay*(i++));
    setTimeout(function() { x += cSize; rZ(0); }, delay*(i++));
    setTimeout(function() { rZ(-180); }, delay*(i++));
    //switch
    setTimeout(function() { 
        x += cSize;
        y -= cSize;
        rZ(0);
        c.css('transform-origin', '0 0 0');
    }, delay*(i++));
    // moving back
    setTimeout(function() { rZ(-90); }, delay*(i++));
    setTimeout(function() { y -= cSize; rZ(0); }, delay*(i++));
    setTimeout(function() { rZ(-90); }, delay*(i++));
    // switch
    setTimeout(function() { 
        y -= cSize; 
        rZ(0);
        c.css('transform-origin', '0 0 '+cSize+'px');
    }, delay*(i++));
    // moving up
    setTimeout(function() { rY(-90); }, delay*(i++));
    setTimeout(function() { z += cSize; rY(0); }, delay*(i++));
    setTimeout(function() { rY(-90); }, delay*(i++));
    // switch
    setTimeout(function() { 
        z += cSize; 
        rY(0); 
        c.css('transform-origin', '0 '+cSize+'px 0');
    }, delay*(i++));
    // moving left
    setTimeout(function() { rZ(90); }, delay*(i++));
    setTimeout(function() { y+= cSize; rZ(0); }, delay*(i++));
    setTimeout(function() { $('#minicube').addClass('grow'); }, delay*(i++));
}

setTimeout(animate, delay*10);
              
            
!
999px

Console