function to close the box with animation