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

+ 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

              
                <div id="button" v-ripple>Button</div>
              
            
!

CSS

              
                #button {
  align-items: center;
  background-color: #4DACFF;
  border: none;
  border-radius: 10px;
  color: white;
  display: flex;
  font-size: 32px;
  height: 120px;
  justify-content: center;
  overflow: hidden;
  position: relative;
  width: 240px;
}

.ripple {
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.4);
  transform: scale(0);
  position: absolute;
  opacity: 1;
}

.rippleEffect {
  animation: rippleDrop .6s linear;
}

@keyframes rippleDrop {
  100% {
    transform: scale(2);
    opacity: 0;
  }
}
              
            
!

JS

              
                new Vue({
  el: "#button",
  directives: {
    ripple: {
      bind: updateRipple,
      unbind: removeRipple
    }
  }
});

// aligned with CSS animation duration
// 与CSS动画时长一致
const RIPPLE_ANIM_DURATION = 600;

function updateRipple(el) {
  "ontouchstart" in document.documentElement
    ? el.addEventListener("touchstart", rippleShow, { passive: true })
    : el.addEventListener("mousedown", rippleShow);
}

function rippleShow(e) {
  // get click/press position
  // 确定点击/触摸位置
  const posX = e.pageX - e.currentTarget.offsetLeft;
  const posY = e.pageY - e.currentTarget.offsetTop;

  // calculate ripple width and height
  // 计算ripple层宽高
  let buttonWidth = e.currentTarget.offsetWidth;
  let buttonHeight = e.currentTarget.offsetHeight;
  buttonWidth > buttonHeight
    ? (buttonHeight = buttonWidth)
    : (buttonWidth = buttonHeight);

  // calculate ripple absolute coordinates
  // 绝对定位添加ripple层
  let spanEl = document.createElement("span");
  spanEl.className = "ripple";
  spanEl.style.width = buttonWidth + "px";
  spanEl.style.height = buttonHeight + "px";
  spanEl.style.top = posY - buttonHeight / 2 + "px";
  spanEl.style.left = posX - buttonWidth / 2 + "px";
  spanEl.classList.add("rippleEffect");

  e.currentTarget.appendChild(spanEl);

  // remove DOM to increase performance
  // 移除DOM提升性能
  setTimeout(() => {
    spanEl.remove();
  }, RIPPLE_ANIM_DURATION);
}

function removeRipple(el) {
  el.removeEventListener("touchstart", rippleShow);
  el.removeEventListener("mousedown", rippleShow);
}

              
            
!
999px

Console