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 id="wheel-container">
<div id="wheel">
  <div id="wi1" data-color="red" class="wheel-item wi1"></div>
  <div id="wi2" data-color="yellow" class="wheel-item wi2"></div>
  <div id="wi3" data-color="green" class="wheel-item wi3"></div>
  <div id="wi4" data-color="purple" class="wheel-item wi4"></div>
  <div id="wi5" data-color="blue" class="wheel-item wi5"></div>
  <div id="wi6" data-color="turqoise" class="wheel-item wi6"></div>
  <div id="wi7" data-color="orange" class="wheel-item wi7"></div>
  <div id="wi8" data-color="pink" class="wheel-item wi8"></div>
</div>
</div>
              
            
!

CSS

              
                body {
  padding: 0;
  margin: 0;
  overflow-x: hidden;
}

#display-text {
  font-size: 50px;
  font-weight: 900;
  margin: 0 auto;
  display: block;
  width: 100%;
  border-bottom: 5px solid red;
}

$containerHeight: 300;
$containerWidth: $containerHeight / 5 * 4;
$containerWidth: $containerHeight;

#wheel-container {
  position: absolute;
  
  height: $containerHeight * 1px;
  width: $containerWidth * 1px;
  right: 0;
  bottom: 0;
  transform: translate(50%, 50%);
  overflow: hidden;
  padding: 50px;
  
  left: 0;
  top: 20px;
  transform: none;
}

  #wheel {
    //background-color: black;
    position: relative;
    height: $containerHeight * 1px;
    width: $containerWidth * 1px;

    &:hover {
      cursor: pointer;
    }

    .wheel-item {
      width: 25%;
      height: 45%;
      float: left;
      background-color: #333;
      //border: 2px solid red;
      z-index: 1;
      position: absolute;
      //left: 400px;
      left: 50%;
      top: 50%;
      transition: all .2s ease-in-out;
      border-radius: 25px;
      
      transform-origin: 50% -1px;

      $colorArr: (
        red,
        yellow,
        green,
        purple,
        blue,
        aqua,
        orange,
        pink,
      );
      $wheelitems: 8;
      $classSlug: wi !default;

      @for $i from 1 through $wheelitems {
        $deg: 180 + ($i - 1) * 45deg;

        &.wi#{$i} {
          transform: rotate(#{$deg});
          z-index: 9 - $i;
          background: nth($colorArr, $i);

          &.active {
            transform: rotate(#{$deg}) scale(1.18);
            z-index: 200;
          }
        }
      }
    }
  }
              
            
!

JS

              
                // card highlight corner
// top-left, top-right, bottom-right, bottom-left
// default: top-left;
var cardHighlight = 'default';

// caching of the container we're building our circle in
var wheel = $('#wheel');

// number of children the container has
var wheelChildren = wheel.children().length;

// snap degree locations - circle is 360deg, wheelChildren is the number of items we have
var rotationSnap = 360/wheelChildren;
var myDraggable;

var clockwise;
var lastRotation = 0;
var overshoot = false;

TweenLite.set(wheel, {xPercent: 0, yPercent: 0});
var transform = wheel[0]._gsTransform;

// function being executed when a card has been chosen and not changed for x seconds
function executeAfterCardChosen(updateText) {
  $('#display-text').text(updateText);
}

// delay after dragging the rotatatatata before executing the defined action 
// that is supposed to happen after an element has been selected
var executionDelay = 1.5;
// the variable holding the timeout trigger made globally available
var timeOutTrigger;

var closestElem;

function activateClosestCard() {
  $('.wheel-item').removeClass('active');
  
  // save wheel width and height
  var wheelWidth  = wheel.width();
  var wheelHeight = wheel.height();
  // default offset is top left
  var cardHighlightOffset = $('#wheel').offset();
  // if another hightlighting type is chosen
  if(cardHighlight == 'top-right') {
    cardHighlightOffset = {left: wheelWidth + cardHighlightOffset.left, top: cardHighlightOffset.top};
  }
  else if(cardHighlight == 'bottom-left') {
    cardHighlightOffset = {left: cardHighlightOffset.left, top: cardHighlightOffset.top + wheelHeight};
  }
  else if(cardHighlight == 'bottom-right') {
    cardHighlightOffset = {left: wheelWidth + cardHighlightOffset.left, top: wheelHeight + cardHighlightOffset.top + 50};
  }
  
  closestElem = $('.wheel-item').closestToOffset(cardHighlightOffset);

  closestElem.addClass('active');
}

function init()
{
  myDraggable = Draggable.create(wheel, {
    type: "rotation",
    throwProps: true,
    minDuration: .5,
    maxDuration: 1,
    throwResistance: 1000,
    overshootTolerance: 1,
    snap: function(endValue) { 
      return Math.round(endValue / rotationSnap) * rotationSnap;
    },
    // after snapping is completed
    onThrowComplete: function() {
      activateClosestCard();
      
      timeOutTrigger = setTimeout(
        function() {
          executeAfterCardChosen(closestElem.prop('id'));
        },
        executionDelay * 1000
      );
    },
    // once dragging starts - not click!
    onDragStart: function() {
      $('.wheel-item.active').removeClass('active');
      
      clearTimeout(timeOutTrigger);
      timeOutTrigger = null;
    },
    // while dragging, event fires ~10 times per second
    onDrag: function() {
      activateClosestCard();
    },
    /*onDragEnd: function() {
      console.log('dragend!!!');
    },
    onRelease: function() {
      console.log('release!!!');
    },
    onLockAxis: function() {
      console.log('lockaxis');
    },
    onThrowUpdate: function() {
      console.log("update!!!");
    },
    onComplete: function() {
      console.log("complete!");
    },*/
  });
}

// initialise circle
init();

jQuery.fn.closestToOffset = function(offset) {
    var el = null,
        elOffset,
        x = offset.left,
        y = offset.top,
        distance,
        dx,
        dy,
        minDistance;
    this.each(function() {
        var $t = $(this);
        elOffset = $t.offset();
        right = elOffset.left + $t.width();
        bottom = elOffset.top + $t.height();

        if (
            x >= elOffset.left &&
            x <= right &&
            y >= elOffset.top &&
            y <= bottom
        ) {
            el = $t;
            return false;
        }

        var offsets = [
            [elOffset.left, elOffset.top],
            [right, elOffset.top],
            [elOffset.left, bottom],
            [right, bottom],
        ];
        for (var off in offsets) {
            dx = offsets[off][0] - x;
            dy = offsets[off][1] - y;
            distance = Math.sqrt(dx * dx + dy * dy);
            if (minDistance === undefined || distance < minDistance) {
                minDistance = distance;
                el = $t;
            }
        }
    });
    return el;
};

var wheelTransformArray = [
  'rotate(360deg)',
  'rotate(315deg)',
  'rotate(deg)',
  'rotate(deg)',
  'rotate(deg)',
  'rotate(135deg)',
  'rotate(deg)',
  'rotate(deg)',
];

$('.wheel-item').click(function() {
  var index = $(this).index();
  var rotateDeg = 360 - (45 * index);
  console.log(index);
  
  TweenMax.to($('#wheel'), 1, {transform: 'rotate(' + rotateDeg + 'deg)'});
});
              
            
!
999px

Console