Morphing Cubes

Ported http://www.webkit.org/blog-files/3d-transforms/morphing-cubes.html to -moz-*. Does it work?

by marcoos

HTML

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">

<html lang="en">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  <title>Morphing Power Cubes</title>
</head>
<body>

  <div class="controls">
    <h1>Animations, Transitions and 3D Transforms</h1>
    <p>This demo shows some more interesting content using 3D transforms, animations and transitions.
      Note that you can still select the text on the the elements, even while they are rotating. Transforms elements remain
        fully interactive.</p>
    <p>Click Toggle Shape to switch between nested cubes and one big ring. Note how the planes move smoothly to their new locations,
      even while the whole shape is rotating. You can even interrupt this transition by clicking again, and they move back smoothly.</p>
    <p>Toggle the Backfaces Visible checkbox to turn backfaces on and off using <code>-webkit-/-moz-backface-visibility</code>.</p>
    <div><button onclick="toggleShape()">Toggle Shape</button></div>
    <div><input type="checkbox" id="backfaces" onclick="toggleBackfaces()" checked><label for="backfaces">Backfaces visible</label></div>
  </div>

  <div id="container">
    <div id="stage">
      <div id="shape" class="cube backfaces">
        <div class="plane one">1</div>
        <div class="plane two">2</div>
        <div class="plane three">3</div>
        <div class="plane four">4</div>
        <div class="plane five">5</div>
        <div class="plane six">6</div>
        <div class="plane seven">7</div>
        <div class="plane eight">8</div>
        <div class="plane nine">9</div>
        <div class="plane ten">10</div>
        <div class="plane eleven">11</div>
        <div class="plane twelve">12</div>
      </div>
    </div>
  </div>
  
</body>
</html>

CSS

body {
       background-color: black;
       color: white;
       font-family: 'Lucida Grande', Verdana, Arial;
       font-size: 12px;
       background-image:  -moz-radial-gradient(center 45deg, circle closest-side, rgba(255, 255,  255, 0.3) 0%, rgba(255, 255, 255, 0) 100%);
       background-image:  -webkit-radial-gradient(center 45deg, circle closest-side, rgba(255,  255, 255, 0.3) 0%, rgba(255, 255, 255, 0) 100%);
      background-repeat: no-repeat;
     }
 
     #container {
       width: 100%;
       height: 700px;
       -webkit-perspective: 800; /* For compatibility with iPhone 3.0, we leave off the units here */
       -webkit-perspective-origin: 50% 225px;
       -moz-perspective: 800; 
       -moz-perspective-origin: 50% 225px;
     }
     #stage {
       width: 100%;
       height: 100%;
       -webkit-transition: -webkit-transform 2s;
       -webkit-transform-style: preserve-3d;
       -moz-transition: -moz-transform 2s;
       -moz-transform-style: preserve-3d;
     }
     
     #shape {
       position: relative;
       top: 160px;
       margin: 0 auto;
       height: 200px;
       width: 200px;
       -webkit-transform-style: preserve-3d;
       -moz-transform-style: preserve-3d;
     }
     
     .plane {
       position: absolute;
       height: 200px;
       width: 200px;
       border: 1px solid white;
       -webkit-border-radius: 12px;
       border-radius: 12px;
       -webkit-box-sizing: border-box;
       -moz-box-sizing: border-box;
       box-sizing: border-box;
       text-align: center;
       font-family: Times, serif;
       font-size: 124pt;
       color: black;
       background-color: rgba(255, 255, 255, 0.6);
       -webkit-transition: -webkit-transform 2s, opacity 2s;
       -webkit-backface-visibility: hidden;
       -moz-transition: -moz-transform 2s, opacity 2s;
       -moz-backface-visibility: hidden;
     }
 
     #shape.backfaces .plane {
       -webkit-backface-visibility: visible;
       -moz-backface-visibility:...

JavaScript

function hasClassName(inElement, inClassName)
     {
         var regExp = new RegExp('(?:^|\\s+)' + inClassName + '(?:\\s+|$)');
         return regExp.test(inElement.className);
     }
 
     function addClassName(inElement, inClassName)
     {
         if (!hasClassName(inElement, inClassName))
             inElement.className = [inElement.className, inClassName].join(' ');
     }
 
     function removeClassName(inElement, inClassName)
     {
         if (hasClassName(inElement, inClassName)) {
             var regExp = new RegExp('(?:^|\\s+)' + inClassName + '(?:\\s+|$)', 'g');
             var curClasses = inElement.className;
             inElement.className = curClasses.replace(regExp, ' ');
         }
     }
 
     function toggleClassName(inElement, inClassName)
     {
         if (hasClassName(inElement, inClassName))
             removeClassName(inElement, inClassName);
         else
             addClassName(inElement, inClassName);
     }
 
     function toggleShape()
     {
       var shape = document.getElementById('shape');
       if (hasClassName(shape, 'ring')) {
         removeClassName(shape, 'ring');
         addClassName(shape, 'cube');
       } else {
         removeClassName(shape, 'cube');
         addClassName(shape, 'ring');
       }
       
       // Move the ring back in Z so it's not so in-your-face.
       var stage = document.getElementById('stage');
       if (hasClassName(shape, 'ring')) {
         stage.style.webkitTransform = 'translateZ(-200px)';
         stage.style.MozTransform = 'translateZ(-200px)';
       }
       else {
         stage.style.webkitTransform = '';
         stage.style.MozTransform = '';
       }
     }
     
     function toggleBackfaces()
     {
       var backfacesVisible = document.getElementById('backfaces').checked;
       var shape = document.getElementById('shape');
       if (backfacesVisible)
         addClassName(shape, 'backfaces');
       else
         removeClassName(shape, 'backfaces');
     }