Homework
Homework — your gallery
Homework — your gallery.
- Build the gallery. Add
<div id="gallery" class="grid">toindex.html. Createjs/views/gallery.jswithrenderGallery(pictures)(a DocumentFragment). Inmain.js, on a successful load, callrenderGallery(pictures). - Prove the fragment's value. Temporarily rewrite it without the fragment (
pictures.forEach(pic => gallery.appendChild(createCard(pic)))). With ~30 cards you won't see a difference, but you get the principle; restore the fragment. - Turn on the reveal. Create
js/observers.jsand callrevealOnScroll([...])at the end ofrenderGallery. Watch the fade-in as you scroll. - Reproduce the "watch forever" trap. Comment out
observer.unobserve(...). Open "Performance"/"Console" and watch the observer being called nonstop. Restoreunobserve.
Required tests:
- Grid test: the gallery shows a card for every picture.
- Reveal test: cards fade in on scroll; with
prefers-reduced-motion, they appear instantly.
To submit: screenshots or a video: (1) the gallery grid, (2) the fade-in effect on scroll.
Next. The gallery works — when all goes well. But the network, in reality, fails: there's loading, empty, error. In lesson 6 we handle every state — and the day APOD returns a video instead of a picture.