Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Lazy loading images With the intersection observer

Juan
November 06, 2018

Lazy loading images With the intersection observer

Juan

November 06, 2018
Tweet

More Decks by Juan

Other Decks in Programming

Transcript

  1. I ❤ • OPEN SOURCE @AMPHTML • INSTRUCTOR @UDEMY •

    ENGINEERING @IMPARTNERPRM • !" @juanlizarazog HI! I AM JUAN LIZARAZO
  2. @juanlizarazog const domRect = element.getBoundingClientRect(); { "x": 418.4375, "y": 172,

    "width": 923.328125, "height": 44, "top": 172, "right": 1341.765625, "bottom": 216, "left": 418.4375 }
  3. @juanlizarazog element.getBoundingClientRect(); 1. element.getClientRects(); 2. Returns a DOMRectList 3. Returns

    the union of these rectangles which is the DOMRect returned by element.getBoundingClientRect(); * Amount of scrolling matters
  4. @juanlizarazog const options = { root: null, rootMargin: '0px', threshold:

    0 } const observer = new IntersectionObserver( callback, options );