Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>JS Bin</title>
</head>
<body>
  <div></div>
  <footer>Click to toggle spinning</footer>
</body>
</html>
 
var div = document.querySelector('div');
var isSpinning = false;
document.addEventListener('click', function() {
  if (!isSpinning) start();
  else stop();
});
function start() {
  div.classList.add('spin');
  isSpinning = true;
}
function stop() {
  div.addEventListener('webkitAnimationIteration', callback);
  div.addEventListener('MSAnimationIteration', callback);
  div.addEventListener('animationiteration', callback);
  
  function callback() {
    div.removeEventListener('webkitAnimationIteration', callback);
    div.removeEventListener('MSAnimationIteration', callback);
    div.removeEventListener('animationiteration', callback);
    div.classList.remove('spin');
    isSpinning = false;
  }
}
Output

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

Dismiss x
public
Bin info
wilsonpagepro
0viewers