Hover caption within movie canvas

I followed the hover caption tutorial but sometimes the hover caption goes out of the movie.

How to make it stay inside the movie and a certain distance of the mouse?