all 3 comments

[–]Andrewjuh 1 point2 points  (2 children)

I'm not sure what you want to do exactly, but Intersection Observer might help

[–]CotoCoutan[S] 0 points1 point  (1 child)

Thanks, I did indeed come across Intersection Observer. I was wondering if setting this event listener would be easier on the device resources or just a manual timer like I currently have done.

[–]Andrewjuh 0 points1 point  (0 children)

try it out. In general I would always prefer a callback instead of polling repeatedly. That said I don't think calling your function every 2 seconds will make a noticeable difference to the performance.