cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

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.

Quick-add: + add another resource

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.

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.

            
              <p id="instruction-text">Press &amp; Hold</p>
<ul id="instruction">
  <li class="nth1"></li>
  <li class="nth2"></li>
  <li class="nth3"></li>
  <li class="nth4"></li>
  <li class="nth5"></li>
  <li class="nth6"></li>
  <li class="nth7"></li>
  <li class="nth8"></li>
  <li class="nth9"></li>
  <li class="nth10"></li>  
</ul>
            
          
!
            
              $background: #222327;
$blue: #3490b7;
$pink: #FF8B87;
$red: #FF4B47;
$green: #40E64F;
$yellow: #E0C93B;
$orange: #F58F39;
$duration: 1.4s;
$num: 9;

@function ring-animation-delay($which){
  @return $duration / $num * $which;
}

* {
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

html {
  font-size: 62.5%;
  overflow: hidden;
}
body {
  height: 100vh;
  width: 100%;
  overflow: hidden;
  background: $background;
  touch-action: none;
}
ul {
  position: absolute;
  display: block;
  width: 50vmin;
  height: 50vmin;
  transition: transform .15s ease, opacity .15s ease, mix-blend-mode .315s ease;
  transform: translate3d(-50%,-50%, 0);
  &:last-of-type {
    //mix-blend-mode: screen;
  }
  li {
    display: block;
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    border: 4vmin solid $blue;
    border-radius: 50%;
    transform: translate3d(0,0,0) scale(1);
    animation: pressed $duration 0s infinite cubic-bezier(.73,.32,.59,1.4) both, fadeOut $duration 0s infinite ease-in both;
    
    &.nth1 {
      animation-delay: ring-animation-delay(0), ring-animation-delay(0);
    }
    &.nth2 {
      border-color: $red;
      animation-delay: ring-animation-delay(1), ring-animation-delay(1);
    }
    &.nth3 {
      border-color: $green;
      animation-delay: ring-animation-delay(2), ring-animation-delay(2);
    }
    &.nth4 {
      border-color: $pink;
      animation-delay: ring-animation-delay(3), ring-animation-delay(3);
    }
    &.nth5 {
      animation-delay: ring-animation-delay(4), ring-animation-delay(4);
    }
    &.nth6 {
      border-color: $yellow;
      animation-delay: ring-animation-delay(5), ring-animation-delay(5);
    }
    &.nth7 {
      border-color: $orange;
      animation-delay: ring-animation-delay(6), ring-animation-delay(6);
    }
    &.nth8 {
      border-color: $green;
      animation-delay: ring-animation-delay(7), ring-animation-delay(7);
    }
    &.nth9 {
      border-color: $yellow;
      animation-delay: ring-animation-delay(8), ring-animation-delay(8);
    }
    &.nth10 {
      border-color: $red;
      animation-delay: ring-animation-delay(9), ring-animation-delay(9);
    }
  }
}

@keyframes fadeOut {
  100% {
    opacity: 0;
  }
}
@keyframes pressed {
  0% {
    transform: translate3d(0,0,0) scale(0);
  }
}
@keyframes fadeIn {
  100% {
    opacity: 1;
  }
}

#instruction-text {
  display: flex;
  justify-content: center;
  color: #ededfb;
  font-size: 5vmin;
  letter-spacing: .045em;
  font-family: -apple-system, "Segoe UI", "Helvetica-Neue", sans-serif;
  height: 90vh;
  align-items: flex-end;
  position: absolute;
  width: 100%;
  z-index: 100;
  animation: fadeIn 8s 0s 2 alternate ease-out;
  opacity: 0;
}
#instruction {
  top: 50vh;
  left: 50%;
  li {
    animation-iteration-count: 5;
  }
}

@-ms-viewport {
  width: device-width;
}
@viewport {
  width: device-width;
}

            
          
!
            
              var NUM = 9;
var MOUSE = 'mouse';
var current = {
  mouse: {},
  pointer: {},
  touch: {},
  actives: {}
};

if (window.PointerEvent) {
  document.body.addEventListener('pointerdown', down, false);
  document.body.addEventListener('pointermove', move, false);
  document.body.addEventListener('pointerup', up, false);
} else {
  document.body.addEventListener('mousedown', down, false);
  document.body.addEventListener('touchstart', down, false);
  
  document.body.addEventListener('touchmove', move, false);
  document.body.addEventListener('mousemove', move, false);

  document.body.addEventListener('mouseup', up, false);
  document.body.addEventListener('touchend', up, false);
}

function down(e) {
  console.log(e.type);
  e.preventDefault();
  var eventType = e.type.replace('down','').replace('start','');
 
  if (eventType === 'pointer') {
    var main = createMain(e, eventType);
    getPointerPressure(e, main);
    getPointerTilt(e, main);
  } else if (eventType === 'touch' && e.changedTouches) {
    e.preventDefault();
    [].slice.call(e.changedTouches).forEach(function(changedTouch) {
      var main = createMain(changedTouch, eventType);
      getTouchForce(e, main);
    });
  } else { //mouse
    var main = createMain(e, eventType);
    getMouseForce(e, main);
  }
}

function createMain(e, eventType) {
  var main = document.createElement('ul');
  var id = e.pointerId || e.identifier || MOUSE; //pointer || touch || mouse
  main.setAttribute('data-id', id);
  current[eventType][id] = main;
  current.actives[id] = {
    main: main,
    left: (e.pageX) + 'px',
    top: (e.pageY) + 'px'
  }
  for (var i = 0; i < NUM; i++) {
    var ring = document.createElement('li');
    ring.className = eventType + ' nth' + (i + 1);
    ring.setAttribute('data-id', id);
    main.appendChild(ring);

    ring.addEventListener('animationiteration', function(e2) {
      if (e2.animationName === 'pressed' && e2.target.classList.contains('ended')) {
        var target = e2.target;
        if (target && target.parentNode) {
          target.style.animation = 'none';
          target.parentNode.removeChild(target);
        }
      }
    });
  }
  document.body.appendChild(main);
  return main;
}

function move(e) {
  var eventType = e.type.replace('move','');
  if (eventType === 'pointer') {
    var main = current[eventType][e.pointerId];
    moveMain(e, e.pointerId);
    getPointerPressure(e, e.pointerId);
    getPointerTilt(e, main);
  } else if (eventType === 'touch' && e.changedTouches) {
    [].slice.call(e.changedTouches).forEach(function(changedTouch) {
      var main = current[eventType][changedTouch.identifier];
      if (main) {
        moveMain(changedTouch, changedTouch.identifier)
        getTouchForce(changedTouch, changedTouch.identifier);
      }
    });
  } else {
    var main = current.mouse.mouse;
    if (main) {
      moveMain(e, MOUSE)
      getMouseForce(e, MOUSE);
    }
  }
}

function moveMain(e, id) {
  var it = current.actives[id];
  it.left = (e.pageX) + 'px',
  it.top = (e.pageY) + 'px'
}

function up (e) {
  var eventType = e.type.replace('up','').replace('end','');
  if (eventType === 'pointer' || eventType === 'mouse') {
    endMain(e, eventType); 
  } else if (e.changedTouches) {
    e.preventDefault();
    [].slice.call(e.changedTouches).forEach(function(changedTouch) {
      endMain(changedTouch, eventType);
    });
  }
}
  
function endMain(e, eventType) {
  var id = e.pointerId || e.identifier || MOUSE;
  [].slice.call(current[eventType][id].querySelectorAll('li')).forEach(function(el) {
    el.classList.add('ended');
  });
  delete current.actives[id];
  delete current[eventType][id];
}




function getPointerPressure(e, el) {
  var pressure = e.pressure;
  if (pressure && pressure != .5 && el) {
    var value = 50 + (Math.min(25 * pressure, 25)) + 'vmin';
    console.log(value);
    el.style.width = value;
    el.style.height = value;
  }
}
function getTouchForce(changedTouch, id) {
  if (changedTouch.force) {
    var value = 50 + (25 * changedTouch.force) + 'vmin';
    current.actives[id].width = value;
  }
}
function getMouseForce(e, id) {
  var force = e.force || e.webkitForce;
  if (force) {
    var value = 50 + (Math.min(10 * force, 25)) + 'vmin';
    current.actives[id].width = value;
  }
}
function getPointerTilt(e, el) {
  var tiltX = e.tiltX;
  var tiltY = e.tiltY;
  if (tiltX != 0 && tiltY != 0 && el) {
    console.log('tilt', tiltX, tiltY);
    var value = 'translate3d(-50%,-50%,0) rotateX('+tiltY+'deg) rotateY('+tiltX+'deg)';
    el.style.transform = value;
  }
}

function animate() {
  for (var key in current.actives) {
    var active = current.actives[key];
    var style = active.main.style;
    style.left = active.left;
    style.top = active.top;
    if (active.width) {
      style.width = active.width;
      style.height = active.width;
    }
  }
  requestAnimationFrame(animate);
}
animate();


document.body.addEventListener('contextmenu', function(e) {
  e.preventDefault();
});


//because touches are weird, and get stuck sometimes... haven't figured out cause yet
// setInterval(function() {
  
// }, 2000)
            
          
!
999px
Loading ..................

Console