Moving objects in a stack animation

Does anyone have an idea on how this can be achieved?

You could possibly do this by adding an attachment to each box, then using a rope constraint to tie each box to the adjacent one.