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>
  <div></div>
</body>
</html>
 
div {
  width: 100px;
  height: 100px;
  border: 1px solid black;
}
 
function transitionEndPromise(element) {
  return new Promise(resolve => {
    element.addEventListener('transitionend', function f() {
      element.removeEventListener('transitionend', f);
      resolve();
    });
  });
}
function requestAnimationFramePromise() {
  return new Promise(resolve => requestAnimationFrame(resolve));
}
function animate(element, stylz) {
  Object.assign(element.style, stylz);
  return transitionEndPromise(element)
    .then(_ => requestAnimationFramePromise());
}
var element = document.querySelector('div');
Object.assign(
  element.style,
  {
    transition: 'transform 1s, background-color 1s',
    backgroundColor: 'red',
    transform: 'translateX(0px)',
  }
);
requestAnimationFramePromise()
  .then(_ => animate(element, {transform: 'translateX(100px)', backgroundColor: 'blue'}))
  .then(_ => animate(element, {transform: 'translateX(50px)', backgroundColor: 'green'}))
  .then(_ => animate(element, {transform: 'translateX(0px)', backgroundColor: 'red'}))
  .then(_ => {
    element.textContent = 'I’m done animating!';
  })
Output

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

Dismiss x
public
Bin info
surmapro
0viewers