Scroll spy algorithm implementation