This library searches for all <img> elements with the lazy class and loads them when they become visible (via a IntersectionObserver), either through scrolling or window resizing.
When triggered, it sets the 'src' attribute from the 'data-lazy-src' value, causing the image to load.
IMPORTANT: I find this class works well with Windows and non-Apple devices- but ipad in particular encounters freezing as Apple runs single threaded.
IMPORTANT: The <img src='myimage.png' loading='lazy'> seems to be a modern non-javascript alternative.
html
The presence of the lazy class will automatically:
_lazyImages object.initLazyImages() to prepare all .lazy images in the DOM for lazy loading.The class also preloads a few additional images ahead of those in view.
For dynamically added images (e.g. via AJAX), you can call:if (_lazyImages) _lazyImages.initLazyImages();
You can also call _lazyImages.initLazyImages() to reinitialize if the DOM has been independently adjusted (e.g. through ajax or hiding and showing elements).
To handle resize and scrolling - you need to factor in events, which should bind(_lazyImages):
js
To run post-processing on each loaded image, either:
const _lazyImages = new MFLazyImages(myCallbackFunc)), orMFLazyImagesCallback(img) function, e.g.javascript
Also see www.robinosborne.co.uk
Also see
articles/How-to-format-html-ready-for-console.logsquarearticles/Implementing-a-Monaco-Editorsquarearticles/iConnectionTestsquarearticles/imagick-fiddlesquarearticles/javascript-camerasquarearticles/list-editsquarearticles/minifierssquarearticles/opayosquarearticles/table-drag-sortersquarearticles/typewatchsquareprojects/MFCalculatorPopupsquareprojects/MFCalendarPopupsquareprojects/MFChartColumnsquareprojects/MFColorPickersquareprojects/MFColorPickerBasicsquareprojects/MFColumnDataBarsquareprojects/MFColumnGradientsquareprojects/MFCropCornerUIsquareprojects/MFFloatawayMsgsquareprojects/MFHourglasssquareprojects/MFLazyImagessquareprojects/MFPanZoomsquareprojects/MFPanelssquareprojects/MFScrollIndicatorssquareprojects/MFSelectorsquareprojects/MFShowConsolesquareprojects/MFTableCellSummingsquare