3 ms·
Is there really no way to determine if an image has left the viewport? This is a solved problem on other platforms: you just cancel image fetches if the image h
by dcow 7y ago
Is there really no way to determine if an image has left the viewport? This is a solved problem on other platforms: you just cancel image fetches if the image has scrolled out of the viewport. No timers needed.
- EdwardDiego 7y agoThere's an IntersectionObserver API that does exactly this - it fires your callback when your configured threshold (X% of element A is intersecting element B) is passed in either direction.
- zamadatix 7y agoSee the second link in my comment (https://developer.mozilla.org/en-US/docs/Web/API/AbortController/abort https://developer.mozilla.org/en-US/docs/Web/API/AbortContro...). Determining if the image is in the viewport is easy, cancelling the async Fetch request after it's been made is an experimental API so not finalized/available everywhere.