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

              
                %h1 Interactive CSS 3D Transform

#tips
    Drag the square around. Also, use your mouse wheel to scale.

#transform

#css
    perspective(500px) rotateX(0deg) rotateY(0deg) scale(1)

              
            
!

CSS

              
                @import compass

@import url(https://fonts.googleapis.com/css?family=Rokkitt)
@import url(https://fonts.googleapis.com/css?family=Numans)

body
  font-family: Numans

#tips, h1
  color: #444
  user-select: none
  margin: 5px
    
#transform
  width: 300px
  height: 300px
  background: #DD312F
  border: 5px solid #444
  color: #444
  margin: 50px auto
  cursor: move
    
#css
  font-family: Rokkitt
  background: #002A38
  border: 1px solid #444
  color: #B98D00
  padding: 10px
  
  &:before
    content: 'transform: '
    color: #D33683
              
            
!

JS

              
                var el          = document.getElementById('transform'),
    css         = document.getElementById('css'),
    width       = el.clientWidth,
    height      = el.clientHeight,
    perspective = 500,
    rotateX     = 0,
    rotateY     = 0,
    scale       = 100,
    isDown      = false,
    reverse     = false,
    lastX,
    lastY;

function scaleVal() {
  var strScale = scale.toString();
  if (scale >= 100) {
    return parseFloat(strScale[0] + '.' +  strScale.slice(1));
  }
  return parseFloat('0.' + strScale);
}

function updateTransform() {
  var pProp = 'perspective(' + perspective +  'px)',
      xProp = 'rotateX('     + rotateX     + 'deg)',
      yProp = 'rotateY('     + rotateY     + 'deg)',
      sProp = 'scale('       + scaleVal()  +    ')',
      props = [pProp, xProp, yProp, sProp].join(' ');
  el.style[Modernizr.prefixed('transform')] = props;
  css.innerText = props;
}

function wheel(e) {
  e.preventDefault();
  var delta = e.wheelDelta || -e.detail;
  scale += delta > 0 ? 5 : -5;
  updateTransform();
}

el.addEventListener('mousedown', function(e) {
  isDown = true;
  lastX  = e.clientX;
  lastY  = e.clientY;
}, false);

el.addEventListener('mousewheel', wheel, false);
el.addEventListener('DOMMouseScroll', wheel, false);

document.addEventListener('mousemove', function(e) {
  if (isDown) {
    xMultiplier = 180 / height / scaleVal();
    yMultiplier = 180 / width  / scaleVal();
    rotateX += (lastY - e.clientY) * xMultiplier;
    rotateY += (lastX - e.clientX) * yMultiplier * (reverse ? 1 : -1);
    rotateX  = Math.floor(rotateX % 360);
    rotateY  = Math.floor(rotateY % 360);
    reverse  = Math.abs(Math.floor(rotateX / 90) % 4) > 1;
    lastX    = e.clientX;
    lastY    = e.clientY;
    updateTransform();
  }
}, false);

document.addEventListener('mouseup', function() {
  isDown  = false;
}, false);
              
            
!
999px

Console