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.

            
              <button class="button" id="button1">I want feedback</button>
<p class="desc">hover button with mouse to see visual feedback</p>
            
          
!
            
              @import url('https://fonts.googleapis.com/css?family=Open+Sans|Prata');

// timing functions
$bounced-timing: cubic-bezier(.64,
.57,
.47,
1.29);
$back-timing: cubic-bezier(0.175,
0.885,
0.320,
1.275);
$ease-out-quint:cubic-bezier(0.230,
1.000,
0.320,
1.000);
$ease-in-quint:cubic-bezier(0.755,
0.050,
0.855,
0.060);
$time-fast: 0.1s;
$time-mid: 0.6s;
$font: 'Prata';
$bg-button: #233142;
$color-text: #ccc; //lighten($bg-button, 20%);
$bg-body: #FD9191;
body {
  background-color: $bg-body;
  font-size: 62.5%;
}

// display only
button {
  position: absolute;
  left: 50%;
  background-color: $bg-button;
  border: none;
  border-radius: 4px;
  color: $color-text;
  font-size: 1.5rem;
  font-family: $font;
  letter-spacing: 2px;
}

// description text
.desc {
  text-align:center;
  font-size: 1rem;
  color:lighten($color-text, 10%);
  font-family: 'Open Sans';
  position: absolute;
  left: 50%;
  top: 35%;
  transform: translate3d(-50%, -35%, 0);
}

// positioning button
#button1 {
  top: 50%;
  transform: translate3d(-50%, -50%, 0);
}

.button {
  display: block;
  width: 340px;
  height: 80px;
  cursor: pointer;
  transition: box-shadow $time-fast linear;
  &:hover {
    box-shadow: 0 10px 0 rgba(0, 0, 0, 0.2);
  }
}


            
          
!
            
              var $btn = document.getElementsByClassName('button');
var mouseObj = {
  mouseCoords: null,
  mousetThreshold: 0.12,
  manageMouseLeave: function(event) {
    event.currentTarget.style.boxShadow = "0 0 0 rgba(0,0,0,0.2)";
    // update btn gradient
    event.currentTarget.style.background = "#233142";
  },
  manageMouseMove: function(event) {
    var dot, eventDoc, doc, body, pageX, pageY;
    
    event = event || window.event; // IE-ism
    target = event.currentTarget;
    // (old IE)
    if (event.pageX == null && event.clientX != null) {
      eventDoc = (event.target && event.target.ownerDocument) || document;
      doc = eventDoc.documentElement;
      body = eventDoc.body;

      event.pageX = event.clientX +
        (doc && doc.scrollLeft || body && body.scrollLeft || 0) -
        (doc && doc.clientLeft || body && body.clientLeft || 0);
      event.pageY = event.clientY +
        (doc && doc.scrollTop || body && body.scrollTop || 0) -
        (doc && doc.clientTop || body && body.clientTop || 0);
    }

    // Use event.pageX / event.pageY here

    //normalize
    //bodyRect = document.body.getBoundingClientRect(),
    var elemRect = target.getBoundingClientRect(),//$btn.getBoundingClientRect(),
        mean = Math.round(elemRect.width / 2);
    //offset   = elemRect.top - bodyRect.top;

    //mouseObj.mouseCoords = {mouse_x: event.pageX - elemRect.left , mouse_y:event.pageY - elemRect.top}
    mouseObj.mouseCoords = {
      mouse_true_x: event.pageX - elemRect.left,
      mouse_x: (event.pageX - elemRect.left - mean) * mouseObj.mousetThreshold,
      mouse_y: event.pageY - elemRect.top
    }
    mouseObj.manageButtonShadow(-1, target);
  },
  manageButtonShadow: function(direction, target) {
    if (mouseObj.mouseCoords) {
      mouseObj.mouseCoords.mouse_x = Math.floor(mouseObj.mouseCoords.mouse_x);
      target.style.boxShadow = direction * mouseObj.mouseCoords.mouse_x + "px 10px 0 rgba(0,0,0,0.2)";
      
      // update btn gradient
      target.style.background = "radial-gradient(at "+mouseObj.mouseCoords.mouse_true_x+"px, #2a3d52 0%, #233142 80%)";

    }
  }
}

// init listeners
for(i=0; i<$btn.length; i++) {
  $btn[i].addEventListener('mousemove', mouseObj.manageMouseMove, false);
  $btn[i].addEventListener('mouseleave', mouseObj.manageMouseLeave, false);
}

            
          
!
999px
Loading ..................

Console