I’ve used jquery’s offset().top, but when running it 4000 times in a loop the browsers freezes for a few seconds. Is there a faster way to get this?
This is happening on the iPAD the desktop is faster.
for (counter=1; counter<4000; counter++)
{
yPos = Math.round($("#star_"+counter).offset().top);
.offset().topalways returns an integer, so rounding it is unnecessary. Furthermore, you can cache the jQuery object for efficiency:UPDATE
Assign a class to each star so you don’t have to keep creating new jQuery objects:
http://api.jquery.com/each
https://developer.mozilla.org/en-US/docs/DOM/element.scrollTop