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 includes JSX processing.

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

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

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 class="stage">
        <div class="pyramid3d">
            <div class="square side1"></div>
            <div class="square side2">נ</div>
            <div class="square side3">ה</div>
            <div class="square side4">ג</div>
            <div class="square side5">פ</div>
            <div class="square small side1"></div>
            <div class="rect side2"></div>
            <div class="rect side3"></div>
            <div class="rect side4"></div>
            <div class="rect side5"></div>
            <div class="triangle side2"></div>
            <div class="triangle side3"></div>
            <div class="triangle side4"></div>
            <div class="triangle side5"></div>
        </div>
    </div>

<div class="instructions">
  <p>Use the arrow keys to rotate the dreidel</p>
  <ul class="arrows">
    <li>&uarr;</li>
    <li>&larr;</li>
    <li>&darr;</li>
    <li>&rarr;</li>
  
  </ul>
</div>
<footer>
  <small>heavily based on <a href="http://www.khemissi.com/examples/css3/010-3D-pyramid/">css3 pyramid</a><br> 
by SelimKhemissi</small>
</footer>
              
            
!

CSS

              
                /* pyramid author : Selim Khemissi http://www.khemissi.com
http://www.khemissi.com/examples/css3/010-3D-pyramid/
*/

.stage {
position:relative;
top: 300px;
width: 150px;
height: 320px;
margin:auto;
perspective:1200px;
perspective-origin:50% 50%;
}

.pyramid3d {
position:relative;
width:200px;
height:200px;
margin:0 auto;

transition: transform 1s ease-out;
transform-style: preserve-3d;
transform: rotateX(50deg) rotateY(0deg) rotate(45deg);
}

.triangle, 
.square {
transform-style:preserve-3d;
transform-origin: left top;
transition: transform 200ms ease-out;
}

.triangle {
width:0;
height:0;
background:none;
}

/* note that border dimension includes border set in '.side' CSS Class */

.triangle:before{
content:"";
position: absolute;
height: 0;
width: 0;
border-style: solid;
/* border-color: rgba(50, 50, 50, 0.7) transparent transparent transparent; */
border-width: 176px 100px 0 100px;
}

.square {
  position:absolute;
  width: 200px;
  height: 200px;
  background: rgba(black, 0.5);
  font-size:8em;
  color:#fff;
  text-align: center;
  font-family: alef, arial;
  font-weight: bold;
  &.small {
    width: 20px;
    height: 20px;
  }
}
.rect {
  width: 20px;
  height: 100px;
  position: absolute;
  background: rgba(black, 0.5);
}

/* note that translation includes border set in '.side' CSS Class */
.side1 {
/* square */
transform: translatez(200px);
background:rgba(0, 0, 0, 0.7);
  &.small {
    transform: translatez(300px) translatex(90px) translatey(90px);

  }
}

.side2 {
  /* triangle */
  transform: translatex(0) rotatey(-125deg) rotatez(90deg);
  &.square {
    background: rgba(black, 0.5);
    transform: translatex(0) translatez(200px) rotatey(-90deg) rotatez(90deg);
  }
  &.rect { 
    background:  rgba(20, 20, 20, 0.3);
    transform: translatex(80px) translatey(50px) translatez(250px) rotatey(90deg) rotatez(90deg);
  }
}

.side3 {
  /* triangle */
  transform: translatex(200px) rotatez(90deg) rotatex(-55deg);
  &.square {
    background: rgba(yellow, 0.5);
    transform: translatex(200px) translatez(200px) translatey(200px) rotatez(-90deg) rotatex(-90deg);  }
  &.rect { 
    background:  rgba(20, 20, 20, 0.3);
    transform: translatex(100px) translatez(250px) translatey(50px) rotatez(-90deg) rotatex(-90deg);
  }
}

.side4 {
  /* triangle */
  transform: translatez(0) rotatex(-55deg);
  &.square {
    background: rgba(blue,0.5);
    transform: translatez(200px) rotatex(-90deg) rotatey(-180deg) translatex(-200px);
  }
  &.rect { 
    transform: translatez(250px) translatey(40px) rotatex(90deg)  translatex(90px);
  }
}

.side5 {

  /* triangle */
  transform: translatey(200px) rotatex(-125deg);
  &.square {
    background: rgba(red, 0.5);
    transform: translatey(200px)  translatez(200px) rotatex(-90deg);
  }
  &.rect {
    transform: translatey(60px) translatex(90px)  translatez(250px) rotatex(-90deg);
  }
}

.side2:before,
.side3:before{ border-color: rgba(20, 20, 20, 0.3) transparent transparent transparent; }
.side4:before,
.side5:before{ border-color: rgba(40, 40, 40, 0.6) transparent transparent transparent; }

.instructions {
  position: absolute;
  bottom: 10px;
  left: 10px;
  background: beige;
  padding: 10px;
  border: 1px solid #999;
  border-radius: 3px;
}
.arrows {
  list-style-type: none;
  padding: 0;
  text-align: center;
  li {
    width: 30px;
    height: 30px;
    line-height: 30px;
    border-radius:3px;
    border: 1px solid #ddd;
    text-align: center;
    display: inline-block;
    background: #fff;
    box-shadow: 1px 2px 0 rgba(black, 0.05);
    &:first-child {
      display: block;
      margin: 0 auto 5px;
    }
  }
}
footer {
  position: absolute;
  right: 10px;
  bottom: 10px;
  width: 200px;
}
a {
  color: #048;
}
              
            
!

JS

              
                /* @author Selim Khemissi http://www.khemissi.com */



(function($) {

    $.cssprefix = function(property) {
        var cssProp = property;
        if($.browser.webkit || $.browser.chrome) {
            cssProp = '-webkit-'+property;
        } else if($.browser.mozilla) {
            cssProp = '-moz-'+property;
        } else if($.browser.msie) {
            cssProp = '-ms-'+property;
        } else if($.browser.opera) {
            cssProp = '-o-'+property;
        }
        return cssProp;
    }

    var SekKeyboard = {
        stdAngle : 45,
        xAngle : 75,
        angleStep : 40,
        scale : 1,
        scaleStep : 0.2,
        initialized:false,
        element:null,
        init:function(element) {
            var self = SekKeyboard;
            if(self.initialized) {
                return;
            }
            self.element = element;
            self.initialized = true;

            $('body').keydown(function(evt) {
                switch(evt.keyCode) {
                case 37: // arrow left
                case 100: // 4 pad
                    evt.preventDefault();
                    self.stdAngle -= self.angleStep;
                    break;

                case 38: // arrow up
                case 104: // 8 numeric pad
                    evt.preventDefault();
                    self.xAngle += self.angleStep;
                    break;

                case 39: // arrow right
                case 102: // 6 numeric pad
                    evt.preventDefault();
                    self.stdAngle += self.angleStep;
                    break;

                case 40: // arrow down
                case 98: // 2 numeric pad
                    evt.preventDefault();
                    self.xAngle -= self.angleStep;
                    break;
                case 107: // + numeric pad
                    evt.preventDefault();
                    self.scale += self.scaleStep;
                    break;

                case 109: // - numeric pad
                    evt.preventDefault();
                    self.scale -= self.scaleStep;
                    break;
                };
                $.rotate3d(self.element, self.xAngle, self.stdAngle, self.scale);
            });

            $('#button_grid_rotation_standard_left').click(function() {
                var self = SekKeyboard;
                self.stdAngle -= self.angleStep;
                $.rotate3d(self.element, self.xAngle, self.stdAngle, self.scale);
            })

            $('#button_grid_rotation_standard_right').click(function() {
                var self = SekKeyboard;
                self.stdAngle += self.angleStep;
                $.rotate3d(self.element, self.xAngle, self.stdAngle, self.scale);
            })

            $('#button_grid_rotation_3dx_up').click(function() {
                var self = SekKeyboard;
                self.xAngle += self.angleStep;
                $.rotate3d(self.element, self.xAngle, self.stdAngle, self.scale);
            })

            $('#button_grid_rotation_3dx_down').click(function() {
                var self = SekKeyboard;
                self.xAngle -= self.angleStep;
                $.rotate3d(self.element, self.xAngle, self.stdAngle, self.scale);
            })

            $('#button_grid_zoom_out').click(function() {
                var self = SekKeyboard;
                self.scale -= self.scaleStep;
                $.rotate3d(self.element, self.xAngle, self.stdAngle, self.scale);
            })

            $('#button_grid_zoom_in').click(function() {
                var self = SekKeyboard;
                self.scale += self.scaleStep;
                $.rotate3d(self.element, self.xAngle, self.stdAngle, self.scale);
            })


        },


    }

    $.fn.keyboard_controls = function() {
        // KEYBOARD COMMAND - GRID VIEW ORIENTATION
        SekKeyboard.init(this);
    }


    $.rotate3d = function(element, xAngle, stdAngle, scale) {
        element.attr('style', $.cssprefix('transform')+': rotateX('+xAngle+'deg) rotate('+stdAngle+'deg) scale('+scale+');');
    }



})(jQuery);


$(document).ready(function() {
    $('.pyramid3d').keyboard_controls();
    setTimeout(function() {
        $.rotate3d($('.pyramid3d'), 90, 320, 1.2);
    }, 1000)
})


              
            
!
999px

Console