Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fastest way to get elements in viewport

Tags:

I am dynamically creating a VERY large HTML file with as many elements as the browser on any given computer can feasibly generate.

I then need to, as the user scrolls, access the elements of a certain type (let's say div) that are actually within the viewport.

The only way I know how to get a list of the elements visible in the viewport is to loop through all elements and then see if their bounds overlap with the current viewport. The problem with this is that there are so many elements in the document that this process can not complete quickly enough to let the browser scroll.

Is there a faster way to get all elements within the viewport?