Check what items are on-screen
For improved readability, this writing style is generally recommended:

if (elements.constructor !== Array) { 
    elements = [elements]; 
}


In conditions with range checks, it's a good practice to organize the elements of the condition by increasing numerical order. So instead of this:


bounds.top+margin &lt; window.innerHeight &amp;&amp; bounds.bottom-margin &gt; 0



This is better:

0 &lt; bounds.bottom - margin &amp;&amp; bounds.top + margin &lt; window.innerHeight