cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource

Code Indentation

     

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.

            
              <div id="cardWrapper" class="auto">
  <div id="card">
    <img src="https://massivepenguin.com/pens/hb3d/01_bg.png" data-depth="18" />
    <img class="layer1" src="https://massivepenguin.com/pens/hb3d/02_trees.png" data-depth="12" />
    <img class="layer2" src="https://massivepenguin.com/pens/hb3d/03_gruffalo_body.png" data-depth="8" />
    <img class="layer3" src="https://massivepenguin.com/pens/hb3d/04_mist.png" data-depth="6" />
    <img class="layer4" src="https://massivepenguin.com/pens/hb3d/05_head.png" data-depth="5" />
    <img class="layer4" src="https://massivepenguin.com/pens/hb3d/06_jaw.png" data-depth="5" />
    <img class="layer5" src="https://massivepenguin.com/pens/hb3d/07_tail.png" data-depth="3" />
    <img class="layer6" src="https://massivepenguin.com/pens/hb3d/08_hellboy.png" data-depth="2" />
    <div id="border">&nbsp;</div>
  </div>
</div>

<button id="autoToggle">Click for pointer control</button>
<div id="instructions">Auto animation</div>
            
          
!
            
              @mixin animation($animate...) {
    $max: length($animate);
    $animations: '';

    @for $i from 1 through $max {
        $animations: #{$animations + nth($animate, $i)};

        @if $i < $max {
            $animations: #{$animations + ", "};
        }
    }
    -webkit-animation: $animations;
    -moz-animation:    $animations;
    -o-animation:      $animations;
    animation:         $animations;
    animation-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
}

@mixin keyframes($animationName) {
    @-webkit-keyframes #{$animationName} {
        @content;
    }
    @-moz-keyframes #{$animationName} {
        @content;
    }
    @-o-keyframes #{$animationName} {
        @content;
    }
    @keyframes #{$animationName} {
        @content;
    }
}


$cardHeight: 70vh;
$animSpeed: 5s;

/* these animations are hard-coded to demonstrate the effect - not prtable in the slightest! */
@include keyframes(rotate-card-base) {
  0% { transform: perspective(550px) rotateX(0deg) rotateY(0deg) }
  10%   { transform: perspective(550px) rotateX(0deg) rotateY(0deg) }
  30%   { transform: perspective(550px) rotateX(20deg) rotateY(-20deg) }
  50%   { transform: perspective(550px) rotateX(20deg) rotateY(20deg) }
  70%   { transform: perspective(550px) rotateX(-20deg) rotateY(20deg) }
  90%   { transform: perspective(550px) rotateX(-20deg) rotateY(-20deg) }
  100% { transform: perspective(550px) rotateX(0deg) rotateY(0deg) }
}

@include keyframes(rotate-trees) {
  0% 	{ transform: perspective(550px) translateZ(90px); left: 0%; top: 0%; }
  10%   { transform: perspective(550px) translateZ(90px); left: 0%; top: 0%; }
  30%   { transform: perspective(550px) translateZ(90px); left: 12%; top: 12%;  }
  50%   { transform: perspective(550px) translateZ(90px); left: -12%; top: 12%; }
  70%   { transform: perspective(550px) translateZ(90px); left: -12%; top: -12%; }
  90%   { transform: perspective(550px) translateZ(90px); left: 12%; top: -12%; }
  100% 	{ transform: perspective(550px) translateZ(90px); left: 0%; top: 0%; }
}

@include keyframes(rotate-gruffalo-body) {
  0% 	{ transform: perspective(550px) translateZ(60px); left: 0%; top: 0%; }
  10%   { transform: perspective(550px) translateZ(60px); left: 0%; top: 0%; }
  30%   { transform: perspective(550px) translateZ(60px); left: 8%; top: 8%;  }
  50%   { transform: perspective(550px) translateZ(60px); left: -8%; top: 8%; }
  70%   { transform: perspective(550px) translateZ(60px); left: -8%; top: -8%; }
  90%   { transform: perspective(550px) translateZ(60px); left: 8%; top: -8%; }
  100% 	{ transform: perspective(550px) translateZ(60px); left: 0%; top: 0%; }
}

@include keyframes(rotate-mist) {
  0% 	{ transform: perspective(550px) translateZ(43px); left: 0%; top: 0%; }
  10%   { transform: perspective(550px) translateZ(43px); left: 0%; top: 0%; }
  30%   { transform: perspective(550px) translateZ(43px); left: 6%; top: 6%;  }
  50%   { transform: perspective(550px) translateZ(43px); left: -6%; top: 6%; }
  70%   { transform: perspective(550px) translateZ(43px); left: -6%; top: -6%; }
  90%   { transform: perspective(550px) translateZ(43px); left: 6%; top: -6%; }
  100% 	{ transform: perspective(550px) translateZ(43px); left: 0%; top: 0%; }
}

@include keyframes(rotate-gruffalo-head) {
  0% 	{ transform: perspective(550px) translateZ(36px); left: 0%; top: 0%; }
  10%   { transform: perspective(550px) translateZ(36px); left: 0%; top: 0%; }
  30%   { transform: perspective(550px) translateZ(36px); left: 5%; top: 5%;  }
  50%   { transform: perspective(550px) translateZ(36px); left: -5%; top: 5%; }
  70%   { transform: perspective(550px) translateZ(36px); left: -5%; top: -5%; }
  90%   { transform: perspective(550px) translateZ(36px); left: 5%; top: -5%; }
  100% 	{ transform: perspective(550px) translateZ(36px); left: 0%; top: 0%; }
}

@include keyframes(rotate-hellboy-bg) {
  0% 	{ transform: perspective(550px) translateZ(22px); left: 0%; top: 0%; }
  10%   { transform: perspective(550px) translateZ(22px); left: 0%; top: 0%; }
  30%   { transform: perspective(550px) translateZ(22px); left: 3%; top: 3%;  }
  50%   { transform: perspective(550px) translateZ(22px); left: -3%; top: 3%; }
  70%   { transform: perspective(550px) translateZ(22px); left: -3%; top: -3%; }
  90%   { transform: perspective(550px) translateZ(22px); left: 3%; top: -3%; }
  100% 	{ transform: perspective(550px) translateZ(22px); left: 0%; top: 0%; }
}

@include keyframes(rotate-hellboy-fg) {
  0% 	{ transform: perspective(550px) translateZ(15px); left: 0%; top: 0%; }
  10%   { transform: perspective(550px) translateZ(15px); left: 0%; top: 0%; }
  30%   { transform: perspective(550px) translateZ(15px); left: 2%; top: 2%;  }
  50%   { transform: perspective(550px) translateZ(15px); left: -2%; top: 2%; }
  70%   { transform: perspective(550px) translateZ(15px); left: -2%; top: -2%; }
  90%   { transform: perspective(550px) translateZ(15px); left: 2%; top: -2%; }
  100% 	{ transform: perspective(550px) translateZ(15px); left: 0%; top: 0%; }
}



html, body {
  height: 100%;
}

body {
  background-color: #000;
}

#cardWrapper {
	position: absolute;
	left: 50%;
	top: 50%;
	transform: translate(-50%, -50%);
}

#card {	
	position: relative;
	width: calc(#{$cardHeight} * 0.70756062767475);
	height: $cardHeight;
	overflow: hidden;
	
	img {
		width: 100%;
		height: 100%;
		position: absolute;
	}
  
  .layer1 {
    z-index: 1;
  }
  .layer2 {
    z-index: 2;
  }
  .layer3 {
    z-index: 3;
  }
  .layer4 {
    z-index: 4;
  }
  .layer5 {
    z-index: 5;
  }
  .layer6 {
    z-index: 6;
  }
}

#border {
	position: absolute;
	box-sizing: border-box;
	width: 100%;
	height: 100%;
	border: 20px solid white;
	display: block; 
  z-index: 7; 
}

#autoToggle {
  border: none;
  background-color: #0275d8;
  color: #fff;
  text-transform: uppercase;
  font-weight: bold;
  font-size: 120%;
  padding: 1em;
  cursor: pointer;
  
  &:hover, &:focus, &:active {
    background-color: lighten( #0275d8, 10% )
  }
}

#instructions {
  position: absolute;
  right: 10px;
  bottom: 0;
  color: #fff;
  font-family: sans-serif;
  text-transform: uppercase;
  font-weight: bold;
  font-size: 300%;
  opacity: 0.3;
}

.auto {
	#card {
		@include animation('rotate-card-base #{$animSpeed} infinite')
	}
	.layer1 {
		@include animation('rotate-trees #{$animSpeed} infinite')
	}
	.layer2 {
		@include animation('rotate-gruffalo-body #{$animSpeed} infinite')
	}
	.layer3 {
		@include animation('rotate-mist #{$animSpeed} infinite')
	}
	.layer4 {
		@include animation('rotate-gruffalo-head #{$animSpeed} infinite')
	}
	.layer5 {
		@include animation('rotate-hellboy-bg #{$animSpeed} infinite')
	}
	.layer5 {
		@include animation('rotate-hellboy-fg #{$animSpeed} infinite')
	}
}
            
          
!
            
              var toggle = document.getElementById("autoToggle");
var inst = document.getElementById("instructions");
var wrapper = document.getElementById("cardWrapper");
var card = document.getElementById("card");
var images = card.getElementsByTagName("img");

function rotate(event) {
  var x = event.clientX;
  var y = event.clientY;
  var w = window.innerWidth;
  var h = window.innerHeight;
  var midpointX = w / 2;
  var midpointY = h / 2;
  var ypos = x - midpointX;
  var xpos = y - midpointY;
  var yval = ypos / midpointX * 20;
  var xval = xpos / midpointY * 20;
  var card = document.getElementById("card");
  card.style.transform =
    "perspective(550px) rotateY(" + yval + "deg) rotateX(" + xval + "deg)";

  for (var i = 1; i < images.length; ++i) {
    var myImg = images[i];
    myImg.style =
      "transform: perspective(550px) translateZ(" +
      myImg.getAttribute("data-depth") / myImg.clientHeight * 5000 +
      "px); left: " +
      yval * myImg.getAttribute("data-depth") * -1 / 20 +
      "%; top: " +
      xval * myImg.getAttribute("data-depth") / 20 +
      "%;";
  }
}
document.addEventListener(
  "mousemove",
  function(event) {
    if (!wrapper.classList.contains("auto")) {
      rotate(event);
    }
  },
  false
);

autoToggle.addEventListener("click", function() {
  if (!wrapper.classList.contains("auto")) {
    wrapper.classList.add("auto");
    toggle.innerHTML = "Click for pointer control";
    inst.innerHTML = "AUTO ANIMATION";
  } else {
    wrapper.classList.remove("auto");
    toggle.innerHTML = "Click for auto animation";
    inst.innerHTML = "POINTER CONTROL";
  }
});
            
          
!
999px
Loading ..................

Console