JSFiddle - React, Tailwind, and code Playground

Deferred promise

HTML

<div class="myStyle"></div>

CSS

.myStyle{
  background:#98bf21;
  height:100px;
  width:100px;
  position:absolute;  
}

JavaScript

$(function(){
	/*
	function doAnimation(){
		$("div").animate({left: '250px'},5000);
    afterAnimation();
  }
  
  function afterAnimation(){
  	alert("Animation done");
  }
  
  doAnimation();
  
  */
function doAnimation(){
    var deferred=$.Deferred();
    $("div").animate({left: '250px'},5000,function(){
    deferred.done(afterAnimation());
    });
    
}

  function afterAnimation(){
  	alert("Animation done");
  } 
function animationFail(){
  	alert("Animation fail");
  } 

doAnimation().promise();

  
})