Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ 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

Auto Save

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=play-trigger></div>
<div class=hand-wrapper>
  <div class=hand>
    <div class=card>
      <div class=front>Front</div>
      <div class=back>Back</div>
    </div>
    <div class=card>
      <div class=front>Front</div>
      <div class=back>Back</div>
    </div>
    <div class=card>
      <div class=front>Front</div>
      <div class=back>Back</div>
    </div>
    <div class=card>
      <div class=front>Front</div>
      <div class=back>Back</div>
    </div>
    <div class=card>
      <div class=front>Front</div>
      <div class=back>Back</div>
    </div>
    <div class=card>
      <div class=front>Front</div>
      <div class=back>Back</div>
    </div>
    <div class="card">
      <div class=front>Front</div>
      <div class=back>Back</div>
    </div>
  </div>
</div>
              
            
!

CSS

              
                @import "bourbon";

/**\
|**| Constants
\**/
$debug: true;                          // <insert description>

$card-width: 7em;                      // <insert description>
$card-height: ($card-width * 1.4);     // <insert description>
$max-hand-size: 10;                    // <insert description>
$fanning-angle: -3deg;                 // <insert description>
$hand-gutter: 60px;                    // <insert description>

$bottom-shadow-color: black;           // <insert description>
$top-shadow-color: black;              // <insert description>

/**\
|**| Mixins
\**/
// Material Shadow mixin
// @credit: CSS-Tricks
// @link:   https://css-tricks.com/snippets/sass/material-shadows-mixin/

/**
 * Computes a top-shadow for a card effect.
 *
 * @param {Number} $depth - depth level
 *
 * @return {List}
 */
@function top-shadow($depth) {
  $primary-offset: nth(1.5 3 10 14 19, $depth) * 1px;
  $blur: nth(1.5 3 10 14 19, $depth) * 4px;
  $color: rgba($top-shadow-color, nth(.12 .16 .19 .25 .30, $depth));

  @return 0 $primary-offset $blur $color;
}

/**
 * Computes a bottom-shadow for a card effect.
 *
 * @param {Number} $depth - depth level
 *
 * @return {List}
 */
@function bottom-shadow($depth) {
  $primary-offset: nth(1.5 3 6 10 15, $depth) * 1px;
  $blur: nth(1 3 3 5 6, $depth) * 4px;
  $color: rgba($bottom-shadow-color, nth(.24 .23 .23 .22 .22, $depth));

  @return 0 $primary-offset $blur $color;
}

/**
 * Gives a card depth effect.
 *
 * @param {Number} $depth - depth level (between 1 and 5)
 *
 * @link https://www.google.com/design/spec/layout/layout-principles.html#layout-principles-dimensionality Google Design
 *
 * @requires {function} top-shadow
 * @requires {function} bottom-shadow
 */
@mixin shadow($depth) {
  @if $depth < 1 {
    box-shadow: none;
  } @else if $depth > 5 {
    @warn "Invalid $depth `#{$depth}` for mixin `card`.";
  } @else {
    box-shadow: bottom-shadow($depth), top-shadow($depth);  
  }
}

/**\
|  | Styles
\**/
.hand-wrapper {
  @if ($debug) {
    border: 1px solid red;
  }
  width: 100%;
  position: absolute;
  bottom: 5px;
  .hand {
    @if ($debug) {
      border: 1px solid blue;
    }
    display: inline-block;
    .card {
      position: relative;
      float: left;
      //display: block;
      background-color: #fff;
      top: 0px;
      width: $card-width;
      height: $card-height;
      @include shadow(1);
      @include transform-style(preserve-3d);
      @include transition(top 0.1s, box-shadow 0.2s); 
      &:hover {
        @include shadow(2);
        top: -20px;
      }
      &.flipped { // Doesnt work because of transforms
        @include transform(rotateY(180deg));
      }
      .front, .back {
        @include backface-visibility(hidden);
        position: absolute;
        width: 100%;
        height: 100%;
      }
      .front {
        @if ($debug) {
          border: solid 1px green;
        }
        @include transform(rotateY(0deg));
      }
      .back {
        @if ($debug) {
          border: solid 1px orange;
        }
        @include transform(rotateY(180deg));
      }
      @for $i from 1 through $max-hand-size {
        // i cards in hand
        &:first-child:nth-last-child(#{$i}),
        &:first-child:nth-last-child(#{$i}) ~ .card {
          // hand fanning
          $current-angle: floor($i/2)*$fanning-angle;
          $current-gutter: floor($i/2)*$hand-gutter;
          @for $j from 1 through $i {
            &:nth-child(#{$j}) {
              @include transform(rotate(#{$current-angle}));
              left: $current-gutter;
            }
            $current-angle: $current-angle + -$fanning-angle;
            $current-gutter: $current-gutter + -$hand-gutter;
          }
        }
      }
    }
  }
}

// BUG: Dragging sometimes causes scroll bars to appear on the page.
//Happens when dragged element goes offscreen
body {
  overflow: hidden;
  margin: 0;
  height: 100vh;
  width: 100vw;
  text-align: center;
}

* {
  box-sizing: border-box;
}
              
            
!

JS

              
                //see https://www.greensock.com/draggable/ for more details.
var $hand      = $('.hand');
var $cards     = $(".card");
var myTarget       = $(".play-trigger");
var overlapThreshold = "50%"; 

function onDrop(dragged, dropped) {
  TweenMax.fromTo(dropped, 0.1, {opacity:1}, {opacity:0, repeat:3, yoyo:true});
  console.log("dropped at x:" + this.x + " y:" + this.y);
}

Draggable.create($cards, {
  zIndexBoost: false,
  cursor: "pointer",
  bounds: window,
  onPress: function() {
    console.log("drag started at x:" + this.x + " y:" + this.y);
  },
  onDragSStart: function() {
    // <scale the card back down and instantiate drag physics>
  },
  onDrag: function(e) {
    if (this.hitTest(myTarget, overlapThreshold)) {
      myTarget.addClass("highlight");
    } else {
      myTarget.removeClass("highlight");
    }
    if (!this.hitTest($('.hand-wrapper'), overlapThreshold)) {
      this.endDrag();
    }
  },
  onRelease: function(e) { 
    //Not triggering mouseout and still counting
    //as hovering if the mouse doesnt move after the drag ends.
    if (this.hitTest(myTarget, overlapThreshold)) {
      onDrop(this.target, myTarget);
    }
    console.log("released at x:" + this.x + " y:" + this.y);
    TweenLite.to(this.target, 0.5, {x: 0, y: 0, ease: Expo.easeOut});
  }
});

var hand = {
  cards: $cards,
  handSize: function() {
    return $('.hand .card').length;
  },
  fanningConstant: -3,
  fanningAngle: function(index) {
    var angle = Math.floor(hand.handSize()/2)*this.fanningConstant;
    return angle + this.fanningConstant*-index;
  },
  gutterConstant: 60,
  gutterWidth: function(index) {
    var gutter = Math.floor(hand.handSize()/2)*this.gutterConstant;
    return gutter + this.gutterConstant*-index;
  }
}

hand.cards.hover(function() {
  TweenLite.to(this, 0, {rotation: 0, scale: 1.5, y: -20});
  TweenLite.to(this, 3, {y: -30, ease: Expo.easeOut});
});

hand.cards.mouseout(function() {
  var index = hand.cards.index(this);
  TweenLite.to(this, 0.5, {rotation: hand.fanningAngle(index), y: 0});
  TweenLite.to(this, 0, {scale: 1});
});

TweenMax.to(hand.cards.eq(0), 0, {rotationY: 180});
TweenLite.to(hand.cards.eq(3), 0, {rotationY: 180});
              
            
!
999px

Console