Kicking in crib?!

J

Baby boy will go down in his crib pretty easy between 7:30 and 8:00. He'll sleep for a few hours and then wake up. He'll then start banging his feet hard onto the matress. Lifts both legs straight up and thumps them down over and over. He also rocks his head from side to side pretty fast and eventually starts to cry. He'll get himself so upset he sometimes spits up all over so I try not to leave him for more than a few minutes. He does this a few times a night.

What on earth is he doing? How do I break him of this habit?