Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery.min.js"></script>
<meta charset=utf-8 />
<title>JS Bin</title>
</head>
<body>
  <div></div>
</body>
</html>
 
div {
  background: #A00;
  width: 50px;
  height: 50px;
}
 
var d = $('div'), p, terminator = $.Deferred();
p = $.when( d.animate(
  {height: 700},
  {
    duration: 10000,
    complete: function() {
      console.log("animation complete");
    },
    done: function() {
      console.log(".animate: done");
      terminator.resolve();
    },
    fail: function() {
      console.log(".animate: fail");
    }
  }
).promise(), terminator );
p.done(function(){
  console.log(".promise: done");
});
p.fail(function() {
  console.log(".promise: fail");
});
//let's stop animation after 2s, and see promises behaviours
setTimeout(function() {
  
  // this triggers done and callback
  // cos even though animation did not run, it went to end state
  //d.stop(true,true);
  // this should trigger fail, since it did not go to end 
  // state, but is triggering done
  terminator.reject();
  d.stop(true,false);
},2000);
Output

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

Dismiss x
public
Bin info
anonymouspro
0viewers