JS to reposition elements when they leave the viewport?

You might look up a snippet of JS code for “lazy loading” images, as this is essentially the test in the opposite direction. It would give you a jump start on what you want to do. Basically, grab the bounding box around your video, see if it’s viewable on the screen, and if not, move it somewhere else.