Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
</head>
<body>
  <dialog>
    <h1>This is a dialog</h1>
    <button id="close">Close</button>
  </dialog>
  <h1>Dialog open close animation</h1>
  <p>Testing a dialog open and close animations using transform to shift off screen.</p>
  <button id="open">Open</button>
  <div id="log"></div>
</body>
</html>
 
@keyframes show {
  0% { 
    opacity: 0; 
    transform: translateY(-10px);
  }
}
@keyframes hide {
  0% {
    transform: none;
    display: block;
  }
  100% {
    display: block;
    opacity: 0;
    transform: translateY(-10px);
  }
}
dialog[open] {
  animation: show var(--duration);
  opacity: 1;
  transform: none;
} 
dialog {
  --duration: 400ms;
  animation: hide var(--duration);
  display: block;
  transform: translateX(-200vw);
  /* The UA applies the following while dialog is :modal,
     we need to preserve it during the animation. */
  position: fixed;
  inset-block-start: 0px;
  inset-block-end: 0px;
  max-width: calc((100% - 6px) - 2em);
  max-height: calc((100% - 6px) - 2em);
}
#log {
  white-space: pre;
  border: 1px solid black;
}
 
document.querySelector('#open').addEventListener('click', () => {
  document.querySelector('dialog').showModal();
});
document.querySelector('#close').addEventListener('click', () => {
  document.querySelector('dialog').close();
}); 
document.querySelector('dialog').addEventListener('transitionstart', (evt) => {
  document.querySelector('#log').textContent += `${Math.round(evt.timeStamp)}ms: transitionstart on ${evt.propertyName}\n`; 
});
Output 300px

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
flackrpro
0viewers