Since your div is positioned absolutely with top and margin-left , you also need to animate them:
$("#shrink-test").animate({ height: 50, top: 125, // 100 + 50 / 2 width: 50, marginLeft: -25 // 50 / -2 });
For a programmatic approach, it would be easier to use a negative margin for the y axis.
source share