JSFiddle - React, Tailwind, and code Playground

HTML

<div class="sample">width is supposed to be animated till 500 but it stops at 300</div>

CSS

.sample{
  width:20px;
height:100px;
background-color:#cccccc;    
}

JavaScript

var myTargetWidth = 500; 

$(document).ready(function(){
    $('.sample').animate( { "width" : myTargetWidth },{
        duration : 5000,      
        step: function(now, fx) {
            if($(this).width() > 200){
              myTargetWidth = 300;
              $(this).stop().animate({ "width" : myTargetWidth },1000);
            }
        }
    });
});