Coding task · JavaScript and TypeScript course · Module 8: Events and the DOM

Exercise: Optimization with Observers

Use IntersectionObserver and passive event listeners to create an efficient page with lazy loading.

Task

The index.js file has two functions. setupLazyLoading(images) should observe the images and copy the address from data-src to src only when an image comes into view. setupScrollProgress(target, onProgress) adds a scroll listener that passes scrollTop to onProgress. Fill in the blanks: ___BLANK1___ is the constructor of the visibility observer, ___BLANK2___ is the observer method that stops observing a loaded image, and ___BLANK3___ is the addEventListener option with which the listener promises not to call preventDefault().