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.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

HTML

            
              - var blocks = 36; //blocks per side
- var blockh = Math.floor(Math.random() * (3))+16;
div.viewport
	div.box
		div.front.side
			- for (var x = 0; x < blocks; x++)
				.div
		div.back.side
			- for (var x = 0; x < blocks; x++)
				.div
		div.left.side
			- for (var x = 0; x < blocks; x++)
				.div
		div.right.side
			- for (var x = 0; x < blocks; x++)
				.div
		div.top.side
			- for (var x = 0; x < blocks; x++)
				.div
		div.bottom.side
			- for (var x = 0; x < blocks; x++)
				.div

            
          
!

CSS

            
              
$blocks: 36;
$width: 200px;
$blue: hsla(51, 100%, 65%, 0.6);
$sideblue: hsla(51, 100%, 62%, 0.3);

@keyframes blockSlide{
	0% { transform: translateX(-$width/1.5) rotateX(90deg); opacity: 1; }
	25% { transform: translateX(0px); opacity:0.2;  }
	75% { transform: translateX(0px); opacity:0.5 }
	100% { transform: translateX($width/1.5) rotateX(-90deg); opacity: 1; }
}
@keyframes startSpin{
	0% {
		opacity: 0;
		transform: rotateY(0deg) rotateX(0deg); }
	100%{ 
		opacity: 1;
		transform: rotateY(360deg) rotateX(360deg); }
}

body{
	background: #222;
	font-size: 100%;
}

.viewport{
	margin-top: calc(50vh - 100px);
	perspective: $width*3;
	transform: scale(0.75,0.75);
}
.box{
	width: $width;
	height: $width;
	position: relative;
	transform-style: preserve-3d;
	transition: transform 1s ease-out; /* essential for clean drag control */
	user-select: none;
  margin: 0 auto 100px;
	animation: startSpin 2s ease-out;
	
	.side{
		background-color: transparent;
		width: $width;
		height: $width;
		display: block;
    position: absolute;
    text-align: center;
    font-weight: bold;
    color: white;
		
		&.front  { transform: rotateZ(   0deg ) translateZ(  $width/2 );}
		&.back   { transform: rotateX( 180deg ) rotateZ(180deg) translateZ(  $width/2 ); }
		&.right  { transform: rotateY(  90deg ) rotateZ(90deg) translateZ( $width/2 );  }
		&.left   { transform: rotateY( -90deg ) rotateZ(-90deg) translateZ( $width/2 );  }
		&.top    { transform: rotateX(  90deg ) rotateZ(-90deg) translateZ( $width/2 );  }
		&.bottom { transform: rotateX( -90deg ) rotateZ(-90deg) translateZ( $width/2 );  }
		
		div{
			transform-style: preserve-3d;
			float:left;
			background: $blue;
			box-shadow: 0px 0px $width/3 10px $sideblue;
			display: inline-block;
			width: $width/sqrt($blocks);
			height: $width/sqrt($blocks);
			margin: 0;
			padding: 0;
			animation: blockSlide 777ms infinite alternate;
			animation-timing-function: easeInOutSine;
			
			
			/* this loop is the unique things */
			/* currently all sides are identical */
			@for $i from 1 through $blocks {
				$time: 20+random(1777) + ms;
				$oldwidth: floor($width/sqrt($blocks));
				$newwidth: (random( $oldwidth )+8)+px;
				$opac: random(10) *.1;
				
				&:nth-child(#{$i}) {
					animation-duration: $time;
					transform: translateZ(random(60)+px);
				}
			}
		}
		
		
	}
}

            
          
!

JS

            
              //Javascript is strictly for camera (viewport) movement
//All the pretty animation occurs in CSS
$(function(){

    var el = document.createElement('div'),
        transformProps = 'transform'.split(' '),
        transformProp = support(transformProps),
        transitionDuration = 'transitionDuration'.split(' '),
        transitionDurationProp = support(transitionDuration);

    function support(props) {
        for(var i = 0, l = props.length; i < l; i++) {
            if(typeof el.style[props[i]] !== "undefined") {
                return props[i];
            }
        }
    }

    var mouse = {
            start : {}
        },
        touch = document.ontouchmove !== undefined,
        viewport = {
            x: -10,
            y: 20,
            el: $('.box')[0],
            move: function(coords) {
							
                if(coords) {
                    if(typeof coords.x === "number") this.x = coords.x;
                    if(typeof coords.y === "number") this.y = coords.y;
                }

                this.el.style[transformProp] = "rotateX("+this.x+"deg) rotateY("+this.y+"deg)";
            },
            reset: function() {
                this.move({x: 0, y: 0});
            }
        };

    viewport.duration = function() {
        var d = touch ? 50 : 500;
        viewport.el.style[transitionDurationProp] = d + "ms";
        return d;
    }();

    $(document).keydown(function(evt) {
        switch(evt.keyCode)
        {
            case 37: // left
                viewport.move({y: viewport.y - 90});
                break;

            case 38: // up
                evt.preventDefault();
                viewport.move({x: viewport.x + 90});
                break;

            case 39: // right
                viewport.move({y: viewport.y + 90});
                break;

            case 40: // down
                evt.preventDefault();
                viewport.move({x: viewport.x - 90});
                break;

            case 27: //esc
                viewport.reset();
                break;

            default:
                break;
        };
    }).bind('mousedown touchstart', function(evt) {
        delete mouse.last;
        if($(evt.target).is('a, iframe')) {
            return true;
        }

        evt.originalEvent.touches ? evt = evt.originalEvent.touches[0] : null;
        mouse.start.x = evt.pageX;
        mouse.start.y = evt.pageY;
        $(document).bind('mousemove touchmove', function(event) {
            // Only perform rotation if one touch or mouse (e.g. still scale with pinch and zoom)
            if(!touch || !(event.originalEvent && event.originalEvent.touches.length > 1)) {
                event.preventDefault();
                // Get touch co-ords
                event.originalEvent.touches ? event = event.originalEvent.touches[0] : null;
                $('.viewport').trigger('move-viewport', {x: event.pageX, y: event.pageY});
            }
        });

        $(document).bind('mouseup touchend', function () {
            $(document).unbind('mousemove touchmove');
        });
    });

    $('.viewport').bind('move-viewport', function(evt, movedMouse) {

        // Reduce movement on touch screens
        var movementScaleFactor = touch ? 4 : 1;
				console.log(movementScaleFactor);
			
        if (!mouse.last) {
            mouse.last = mouse.start;
        } else {
            if (forward(mouse.start.x, mouse.last.x) != forward(mouse.last.x, movedMouse.x)) {
                mouse.start.x = mouse.last.x;
            }
            if (forward(mouse.start.y, mouse.last.y) != forward(mouse.last.y, movedMouse.y)) {
                mouse.start.y = mouse.last.y;
            }
        }

        viewport.move({
            x: viewport.x + parseInt((mouse.start.y - movedMouse.y)/movementScaleFactor),
            y: viewport.y - parseInt((mouse.start.x - movedMouse.x)/movementScaleFactor)
        });

        mouse.last.x = movedMouse.x;
        mouse.last.y = movedMouse.y;

        function forward(v1, v2) {
            return v1 >= v2 ? true : false;
        }
    });

});
            
          
!
999px

Console