One broader question. Is there a reason why you are using the DOM as opposed to the using the canvas for something like this?
You can certainly do all of this using the DOM, but the Canvas is designed for arbitrary pixels moving and related interactivity parts. The DOM is more for HTML elements and how to ensure we can present them well.
A lot of what you are doing may be easier since you are dealing with fixed coordinates. Given all that you know about JS already, you may find canvas to be an easy pickup
Creating engaging and entertaining content for designers and developers since 1998.