Lightweight Javascript Plugin for Image Lazy Loading | justlazy.js

justlazy.js is a lightweight javascript plugin for responsive image loading. Most of the current javascript plugins use extensive dependencies or only support the img tag with no responsive parts. This plugin is meant to be an alternative.

  • 100% performance using plain javascript (no jQuery).
  • 100% valid HTML (no empty src tag).
  • Simplicity and lightness (only lazy loading of images, no special cases).
  • Extensively tested on various devices, browsers, and OS versions.

lazy load images example, lazy load images jquery, lazy load background images, lazy loading javascript on scroll, lazy load images html, lazy loading example

How to make use of it:

1. Install, download, and import the following JavaScript and CSS files into your document.

# NPM
$ npm install justlazy --save
<link rel="stylesheet" href="stylesheets/justlazy.css">
<script src="javascript/justlazy.js"></script>

2. Insert the image you want to load slowly using the following HTML data attributes:

<div class="load-if-visible-placeholder justlazy-spinner" 
     data-src="1.jpg" 
     data-alt="Image Alt" 
     data-title="Image Title">
</div>

3. Activate the lazy load image plugin.

Justlazy.registerLazyLoadByClass("load-if-visible-placeholder");

4. Specify the millisecond limit in which the xxx pixel image will be loaded before it becomes visible on the screen.

Justlazy.registerLazyLoadByClass("load-if-visible-placeholder",{
  threshold: 300
});

5. Callback functions:

Justlazy.registerLazyLoadByClass("load-if-visible-placeholder",{
  // Optional callback which is invoked after the image is loaded successfully but before the actual replacement.
  onloadCallback: function(){},
                              
  // Optional error handler which is invoked before the actual replacement if the image could not be loaded.
  onerrorCallback: function(){},
  // Optional callback which is invoked directly after the replacement of the placeholder.
  onreplaceCallback: function(){},
                                
});

image lazy load with custom events, justlazy.js Plugin/Github


See Demo And Download

Official Website(fhopeman): Click Here

This superior jQuery/javascript plugin is developed by fhopeman. For extra advanced usage, please go to the official website.

Related Posts

Cookie-Consent-Using-Bootstrap

How to Create a Simple Cookie Banner Consent Using Bootstrap 4

Cookie Consent Popup Javascript – Quick and simple tutorial for creating a simple Bootstrap cookie banner. If you have a website or blog with people visiting or…

Create-HTML-Terminals

Create Custom HTML Terminals With Pure JavaScript | shell.js

Custom HTML Terminals is A JavaScript library to create HTML terminals on web pages. The shell js JavaScript library offers a straightforward method to create Ubuntu, OS X,…

Bootstrap-Alert-Bootbox

Bootstrap Alert, Confirm, and Flexible Dialog Boxes | Bootbox

Bootbox.js is a small JavaScript library that allows you to create programming dialogs using Bootstrap templates, without having to worry about creating, managing, or removing any required…

Slider-fg-carousel

An Accessible Touch-enabled Slider Web Component | fg-carousel

fg-carousel Slider – A simple & modern slider web component to create versatile, accessible, touch-enabled picture carousels utilizing CSS scroll snap, Custom Element, and Intersection Observer API….

Tags-Input-Component

A Lightweight and Efficient Tags Input Component in Vanilla JS | tagify

tagify transforms an input field or textarea into a tags component, in an easy and customizable way, with great performance and a small code footprint, full of…

copy-to-clipboard-javascript

A Lightweight Library to Copy Text to Clipboard | CopyJS

CopyJS is a lightweight JavaScript library that allows you to copy plain text or HTML content to the clipboard. Must Read: Tiny Library for Copy Text In…