Pen Settings

HTML

CSS

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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ 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

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.

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

              
                <main>
  <section class="card">
    <div class="ripple-container">
      <div class="ripple"></div>
    </div>
  </section>
  
  <section class="content">
    <div class="circle-container">
      <div class="circle"></div>
    </div>
  </section>
</main>
              
            
!

CSS

              
                * {
  box-sizing: border-box;
}

html, body {
  height: 100%;
  min-height: 100%;
  background: #eee;   
}

main {
  height: 100vh;
  display: flex;
  flex-direction: column;
  position: relative;
  visibility: hidden;
  opacity: 0;
}

.card {  
  background: #eee;  
  height: 400px;
  min-height: 150px;
  max-height: 40vh;
  overflow: hidden;
  position: relative;
  background-color: #fff;
  box-shadow: 
    0 2px 2px 0 rgba(0, 0, 0, 0.14), 
    0 1px 5px 0 rgba(0, 0, 0, 0.12), 
    0 3px 1px -2px rgba(0, 0, 0, 0.2);
}

.content {
  position: relative;
  flex: 1;
}

.circle-container,
.ripple-container {  
  position: relative;
  width: 100px;
  height: 100px;
}

.circle-container {
  top: 50px;
  left: 10vw;
}

.ripple-container {
  position: absolute;
  top: 0;
  left: 0;
}

.circle,
.ripple {
  position: absolute;
  width: 100px;
  height: 100px;
  top: 50%;
  left: 50%;  
  border-radius: 50%;
  cursor: pointer;
  background: #ff9800;
}

              
            
!

JS

              
                console.clear();
var log = console.log.bind(console);

var kappa = 0.551915024494;

var circleContainer = document.querySelector(".circle-container");
var rippleContainer = document.querySelector(".ripple-container");
var circle = document.querySelector(".circle");
var ripple = document.querySelector(".ripple");
var card = document.querySelector(".card");
var root = document.documentElement;
var body = document.body;

var p0 = { x: 0, y: 0 };
var p1 = { x: 0, y: 0 };
var p2 = { x: 0, y: 0 };
var p3 = { x: 0, y: 0 };

var bezier = { values: [p0, p1, p2, p3], type: "cubic" };
var cursor = { x: 0, y: 0 };

var circleBounds = getBounds(circleContainer);
var rippleBounds = getBounds(card);

var radius = circleBounds.w2;
var padding = -radius;
var duration = 0.4;
var requestId = null;

var standardCurve = new CustomEase("standardCurve", "0.4, 0.0, 0.2, 1");
TweenLite.defaultEase = standardCurve;

TweenLite.set([circle, ripple], { xPercent: -50, yPercent: -50 });

var tl = new TimelineMax({ reversed: true });

update();

circle.addEventListener("click", toggleAnimation);
ripple.addEventListener("click", toggleAnimation);
window.addEventListener("resize", requestUpdate);

TweenLite.set("main", { autoAlpha: 1 });

function toggleAnimation() {
  tl.reversed(!tl.reversed());
}

function update() {
  
  var progress = tl.progress() || 0;
  var reversed = tl.reversed() || false;
  
  tl.progress(0).clear();
  
  circleBounds = getBounds(circleContainer);
  rippleBounds = getBounds(card);
  
  updateBezier();
  
  var delay = getDelay();
  
  var dt = duration - delay;
  var dx = rippleBounds.w2;
  var dy = rippleBounds.h2;
  var tx = dx - radius - p3.x;
  var ty = dy - radius - p3.y;
  
  var size = Math.sqrt(dx * dx + dy * dy) * 2;
  
  TweenLite.set(rippleContainer, { x: tx, y: ty });
  
  tl.to([circle, ripple], duration, { bezier }, 0)
    .to(ripple, dt, { width: size, height: size }, delay)
    .to(circle, dt, { autoAlpha: 0, scale: 0 }, delay)
    .progress(progress)
    .reversed(reversed);
  
  requestId = null;
}

function updateBezier() {
  
  p3.x = rippleBounds.cx - circleBounds.cx;
  p3.y = rippleBounds.cy - circleBounds.cy;
  
  var dx = p3.x - p0.x;
  var dy = p3.y - p0.y;

  if (p3.y > p0.y) {

    p1.x = p0.x;
    p1.y = p0.y + (dy * kappa);  
    p2.x = p3.x - (dx * kappa);
    p2.y = p3.y;

  } else {

    p1.x = p0.x + (dx * kappa);
    p1.y = p0.y;  
    p2.x = p3.x;
    p2.y = p3.y - (dy * kappa);
  }
}

function getDelay() {
  
  cursor.x = p0.x;
  cursor.y = p0.y;
   
  var k = 0.0001;
  
  var cx = circleBounds.cx;
  var cy = circleBounds.cy;
  
  var rx = rippleBounds.x + padding;
  var ry = rippleBounds.x + padding;
  var rw = rippleBounds.w - padding * 2;
  var rh = rippleBounds.h - padding * 2;  
  
  var delay = 0;
  
  var tween = TweenLite.to(cursor, duration, { bezier, paused: true });
  
  for (var i = 0; i <= 1; i += k) {

    tween.progress(i);
    
    var x = cx + cursor.x;
    var y = cy + cursor.y;
    
    if (pointInRect(x, y, rx, ry, rw, rh)) {
      delay = tween.time();
      break;
    }
  }
  
  return delay;
}

function getBounds(element) {
  
  var rect = element.getBoundingClientRect();
    
  var scrollTop  = window.pageYOffset || root.scrollTop  || body.scrollTop  || 0;
  var scrollLeft = window.pageXOffset || root.scrollLeft || body.scrollLeft || 0;

  var clientTop  = root.clientTop  || body.clientTop  || 0;
  var clientLeft = root.clientLeft || body.clientLeft || 0;
    
  var x = Math.round(rect.left + scrollLeft - clientLeft);
  var y = Math.round(rect.top  + scrollTop  - clientTop);  
  
  var w = rect.width;
  var h = rect.height;
  var w2 = w / 2;
  var h2 = h / 2;
  var cx = x + w2;
  var cy = y + h2;  
  
  return { x, y, w, h, w2, h2, cx, cy };
}

function requestUpdate() {
  if (!requestId) {
    requestId = requestAnimationFrame(update);
  }
}

function pointInRect(px, py, rx, ry, rw, rh) {
  return px >= rx && py >= ry && px <= rx + rw && py <= ry + rh;
}

              
            
!
999px

Console