This is a simple trick. You set transitions on both states, like this:
When you hover over, the :hover transition overrides the transition set in the regular state, and that property animates. When you hover off, the transition from the regular state takes over and that property animates.
And now, here an offensively lame examples that you should never use: