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 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.

            
              <link rel="stylesheet" href="https://www.google.com/fonts#UsePlace:use/Collection:Open+Sans:600">
<div id="shape" class="circle"></div>
<div id="shadow"></div>
<div id="toggle">Click to toggle shape</div>
  
  <div id="infos"><a href="https://twitter.com/ayamflow" target="_blank">@ayamflow</a> // <a href="http://ayamflow.fr" target="_blank">ayamflow.fr</a></div>
            
          
!
            
              body {
  background-color: #16a085;
}

#shadow {
  width: 20px;
  height: 5px;
  background: #000;
  opacity: 0.2;
  position: absolute;
  border-radius: 50%;
  -webkit-transform: scaleX(2);
  margin-left: -10px;
}

#toggle {
  width: 220px;
  height: 40px;
  border-radius: 3px;
  text-align: center;
  white-space: nowrap;
  position: absolute;
  border-radius: 4px;
  font-family: 'Open Sans';
  font-weight: 600;
  box-shadow: 0px 2px darken(#c0392b, 20%);
  color: #FFF;
  line-height: 40px;
  text-transform: uppercase;
  bottom: 10px;
  right: 10px;
  background-color: #c0392b;
  
  &:hover {
    cursor: pointer;
    box-shadow: 0px 1px darken(#c0392b, 20%);
      height: 38px;
      bottom: 8px;
  }
}
  
#shape {
  width: 50px;
  height: 50px;
  background-color: white;
  position: absolute;
  -webkit-transform-origin: center center;
  -webkit-transition: border-radius 0.3s cubic-bezier(0.19, 1, 0.22, 1);
    margin-left: -25px;
    margin-top: -25px;
    border-radius: 3px;
    
    &.circle {
      border-radius: 50%;
    }
}

#infos {
  position: absolute;
  right: 250px;
  height: 40px;
  line-height: 40px;
  bottom: 10px;
  color: #FFF;
  a {
    font-family: "Open Sans";
    color: #FFF;
    font-size: 11px;
    text-decoration: none;
    text-shadow: 1px 1px rgba(0, 0, 0, 0.3);
  }
}
            
          
!
            
              console.clear();

var $shape = document.getElementById('shape');
var $shadow = document.getElementById('shadow');
var $toggle = document.getElementById('toggle');
var rectangle = false;
var resetTimer;

var mouse = {
  x: 0,
  y: 0,
  ox: 0,
  oy: 0,
  move: function(event) {
    this.ox = this.x;
    this.oy = this.y;
    this.x = event.pageX;
    this.y = event.pageY;
    
    moveShape();
    clearTimeout(resetTimer);
    resetTimer = setTimeout(reset, 40);
  }
};

var time = Date.now(), speed = 0;
window.addEventListener('mousemove', mouse.move.bind(mouse));
window.addEventListener('click', toggleShape);

function update() {
    requestAnimationFrame(update);
    var elapsed = Date.now() - time;
    var dist = pDist(mouse.x, mouse.y, mouse.ox, mouse.oy);
    speed = dist / elapsed;
    time = Date.now();
}

function pDist(x1, y1, x2, y2) {
  return Math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
}

function toggleShape() {
  rectangle = !rectangle;
  TweenMax.set($shape, {className: rectangle ? '-=circle' : '+=circle'});
  TweenMax.set($shape, {scaleX: 0, scaleY: 0});
  TweenMax.to($shape, 0.2, {scaleX: 1, scaleY: 1, ease: Back.easeOut, easeParams: [5]});
}

function moveShape() {
  var angle = Math.atan2(mouse.y - mouse.oy, mouse.x - mouse.ox) * 180 / Math.PI;
    var scale = Math.max(1, Math.min(3, speed));
  TweenMax.to($shape, 0.1, {x: mouse.x, y: mouse.y, scaleX: scale, rotation: angle, ease: Expo.easeOut});
  TweenMax.to($shadow, 0.1, {x: mouse.x, y: mouse.y + 60, scaleY: scale, ease: Expo.easeOut});
}

function reset() {
    TweenMax.to($shape, 0.1, {scaleX: 1, scaleY: 1, ease: Expo.easeOut});
}

update();
            
          
!
999px
Loading ..................

Console