cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - Activehtmlicon-personicon-teamoctocatspinnerstartv

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.

            
              <main>
  <div>
    <div class="rotate-a thing"><div class="rotate-a--reverse">I am a box!</div></div>
  </div>
  <div>
    <rad-slider name="a" :degree="a" @rotate="rotate"></rad-slider>
  </div>
  <footer>
    <b>Key bindings</b> <span>shift: 15º</span> <span>command: 30º</span> <span>shift + command: 45º</span>
  </footer>
</main>
            
          
!
            
              @import url('https://fonts.googleapis.com/css?family=BenchNine');

:root {
  --a: 0deg;
  --color1: #d41459;
  --color2: #f26191;
}

// add these as needed
.rotate-a {transform: rotate(var(--a));}
.rotate-a--reverse {transform: rotate(calc(0deg - var(--a)));}

// slider
.rad-slider {
  --degree: 0deg;
  --degree-reverse: calc(0deg - var(--degree));
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 25vmin;
  height: 25vmin;
  color: #fff;
  border: .2em solid;
  border-radius: 50%;
  transition: box-shadow 300ms linear;
  transform: rotate(var(--degree));
  .label {
    user-select: none;
    pointer-events: none;
    transform: rotate(var(--degree-reverse));
  }
  &::before {
    content: '';
    position: absolute;
    top: 5%;
    bottom: 70%;
    left: 50%;
    transform: translate(-50%, 0%);
    width: .2em;
    max-height: 2em;
    border-radius: 1em;
    background: #fff;
  }
  &:hover {
    cursor: -webkit-grab;
    box-shadow: 0 0 3em -1em var(--color1);
  }
  &.moving {
    cursor: -webkit-grabbing;
    box-shadow: 0 0 3em -.5em var(--color1);
  }
}

// some style opinions
.rad-slider {
  &:not(.dirty) .label {
    opacity: 1;
  }
  .label {
    position: absolute;
    left: 50%;
    top: 5%;
    width: 3em;
    height: 3em;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 2000ms linear 2000ms;
    opacity: .5;
  }
  &:hover .label {
    transition-duration: 600ms;
    transition-delay: 0ms;
    opacity: 1;
  }
}








.thing {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center; 
  width: 35vmin;
  height: 35vmin;
  font-size: 1.3em;
  border-radius: .3em;
  color: var(--color2);
  background: #fff;
  box-shadow: 0 0 2em -.5em;
}

// boring layout demo structure
*, *::before, *::after {box-sizing: border-box;}

body {
  margin: 0;
  height: 100vh;
  display: flex;
  font-family: BenchNine, sans-serif;
  font-size: 2.5vmin;
  overflow: hidden;
}
main {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: linear-gradient(130deg, #333 65%, var(--color2) 65%);
  > div {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center; 
    &:first-of-type {
      flex: 1.5;
      margin-right: 35%;
    }
    &:last-of-type {
      margin-left: 65%;
    }
  }
}
footer {
  background: #fff;
  color: #363638;
  display: flex;
  > * {
    flex: 1;
    padding: 1em;
    text-align: center;
  }
}

            
          
!
            
              Vue.component('rad-slider', {
  template: `
    <div 
        class="rad-slider"
        :name="name"
        :class="{moving: moving, dirty: dirty}" 
        @mousedown="start" 
        @mousemove="move" 
        @mouseup="stop"
        @touchstart="start" 
        @touchmove="move" 
        @touchend="stop"
        >
      <div class="label">{{degree}}&deg;</div>
    </div>
  `,
  props: {
    name: {
      type: String,
      required: true
    },
    degree: {
      type: Number,
      default: 0
    }
  },
  data: function() {
    return {
      minDegree: 0,
      maxDegree: 360,
      moving: false,
      dirty: false
    }
  },
  mounted: function() {
    this.processDegree(this.degree)
  },
  beforeUpdate: function() {
    this.processDegree(this.degree)
  },
  methods: {
    keepValueInRange: function(value, min, max) {
      let newValue = (value >= max ? value - max : (value < min ? value + max : value))
      return newValue
    },
    processDegree: function(value){
      this.degree = this.keepValueInRange(value, this.minDegree, this.maxDegree)
      this.$el.style.setProperty('--degree', this.degree + 'deg')
      this.$emit('rotate', this.name, this.degree + 'deg')
    },
    getPointerDeg: function(e){
      let x = e.touches && e.touches.length ? e.touches[0].clientX : e.clientX
      let y = e.touches && e.touches.length ? e.touches[0].clientY : e.clientY
      return Math.floor(Math.atan2(x - (this.metrics.left + this.metrics.width/2), y - (this.metrics.top + this.metrics.height/2))*(-180/Math.PI)) + 180
    },
    start: function(e) {
      this.moving = true
      this.dirty = true
      this.metrics = e.target.getBoundingClientRect()
      this.pointer = this.getPointerDeg(e) - this.degree
    },
    move: function(e) {
      if(this.moving) {
        let step = 1
        let input = this.getPointerDeg(e)
        if(e.shiftKey && e.metaKey) {
          step = 45
        } else if(e.shiftKey) {
          step = 15
        } else if(e.metaKey) {
          step = 30
        }
        this.degree = Math.ceil((this.getPointerDeg(e) - this.pointer) / step) * step
        this.processDegree(this.degree)
      }
    },
    stop: function(e) {
      this.moving = false
    }
  }
})

let vm = new Vue({
  el: 'main',
  data: {
    a: 120
  },
  methods: {
    rotate: function(name, degree) {
      document.documentElement.style.setProperty('--' + name, degree)
    }
  }
})

            
          
!
999px
Close

Asset uploading is a PRO feature.

As a PRO member, you can drag-and-drop upload files here to use as resources. Images, Libraries, JSON data... anything you want. You can even edit them anytime, like any other code on CodePen.

Go PRO

Loading ..................

Console