Get all elements in viewport Javascript -


i wonder if possible (in javascript or jquery without plugins) elements (for example table rows tr) in current viewport without looping through each of them? found lot of examples how check if specified element in current viewport, need function returns list of elements in current viewport. need virtualization because table should have infinite capacity , looping through each row 2 millions rows quite inefficient :)

is there reasonable way this?

assuming you're not doing fancy positioning, table rows in viewport can found binary search. example, 200000 rows, 18 lookups required locate first row on page (jsfiddle, warning: slow load). can extended find last element well, or loop through elements starting first until find 1 no longer visible.

var rows = table.children().children(); var start = 0; var end = rows.length; var count = 0;  while(start != end) {     var mid = start + math.floor((end - start) / 2);     if($(rows[mid]).offset().top < document.documentelement.scrolltop)         start = mid + 1;     else         end = mid; } 

obviously not work if floated, absolutely positioned, etc. in short: nodes being searched must in order such rows[n-1].top <= rows[n].top. such table, should true if no styling applied , no multi-row cells exist.


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -