UI › LAYER
SINCE 1.0.0

Layer

Minimal popup API with Promise result, plus SweetAlert-like SVG icon animations powered by xjs.draw() / spring easing.

Quick demo

Open popups
JavaScript
HTML
CSS
// Bind the buttons below (selector + click handlers)
// Icon buttons: read config from data-layer-* and open popup on click
xjs('[data-layer-icon]').layer();

// Confirm flow: custom handler so we can handle the Promise result
xjs('.btn.confirm').forEach((el) => {
  // Idempotent binding (in case this demo re-inits)
  if (el._xjsConfirmHandler) el.removeEventListener('click', el._xjsConfirmHandler);
  el._xjsConfirmHandler = () => {
    xjs.layer({
      title: 'Delete item?',
      text: 'This action cannot be undone.',
      icon: 'question',
      showCancelButton: true,
      confirmButtonText: 'Delete',
      cancelButtonText: 'Cancel'
    }).then((res) => {
      if (res.isConfirmed) {
        xjs.layer({ title: 'Deleted', text: 'Done', icon: 'success' });
      } else if (res.dismiss === 'cancel') {
        xjs.layer({ title: 'Cancelled', text: 'Nothing happened', icon: 'info' });
      }
    });
  };
  el.addEventListener('click', el._xjsConfirmHandler);
});
<button class="btn success" data-layer-title="Success" data-layer-text="SVG icon draw + spring entrance" data-layer-icon="success">Success</button>
<button class="btn error" data-layer-title="Error" data-layer-text="SVG icon draw + spring entrance" data-layer-icon="error">Error</button>
<button class="btn warning" data-layer-title="Warning" data-layer-text="SVG icon draw + spring entrance" data-layer-icon="warning">Warning</button>
<button class="btn info" data-layer-title="Info" data-layer-text="SVG icon draw + spring entrance" data-layer-icon="info">Info</button>
<button class="btn confirm">Confirm</button>
/* This page's button styles are local.
   Layer's own CSS is injected by layer.js */
功能说明:Layer 的 icon 现在是内联 SVG(ring + mark),打开弹窗时会自动触发描边动画;弹窗支持 ESC 关闭(可用 closeOnEsc:false 关闭)。
Tip: try pressing ESC while the popup is open.
icon
success | error | warning | info
iconAnimation
true (default)
popupAnimation
true (default)
closeOnEsc
true (default)
Previous
Next