Lazy-loading Images in JavaScript

Plain, efficient JavaScript, not extra library needed.

Design Goal

HTML

Event-Listener

Callback

Getting the relevant elements

Getting the current view box

Selecting and modifying elements

Optional: Optimizing the execution

Define minimum view-box change

De-register Event Listener

  • Complete code example
  • Cover is called the “Unofficial JavaScript Logo” by Chris Williams licensed WTFPL

Feel free to share your thoughts or ask a question!

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Yannik Schmidt

Python programmer at heart, Linux Expert at work, GameDev on my good days, web developer on the bad days.