Simple & Lightweight Lazy-loading Image Plugin – Echo.js

Looking for a affordable website?

GET STARTED
www.codingexpertz.com
Simple & Lightweight Lazy-loading Image Plugin – Echo.js

File Size: 88KB

Total Views: 3729

Date Created:

Last Modified Date:

Official Website: Go to website

License:

Echo.js is a very simple, lightweight and easy accessible jQuery lazy-loading image plugin that creates lazy-loading effect instantly to any images. It simply needs HTML5 data-* attributes to add lazy-loading for respective images. It also supported on background images, simply add the data-echo-background attribute to the element with the image URL.

Features:

  • Lightweight and easily accessible.
  • Very simple to implement.
  • Supports on all modern browsers and devices.
  • Various predefined options that can be customized easily.

How to use it:

1. Include the Javascript echo.min.js at the bottom of the web page.

<script src="path/to/echo.min.js"></script>

2. Add the basic HTML to the page.

<img src="img/blank.gif" alt="Photo" data-echo="img/photo.jpg">
<img src="img/blank.gif" alt="Photo" data-echo-background="img/photo.jpg">

3. Initialize the plugin and we’re ready to go.

echo.init({
  offset: 100,
  throttle: 250
});

Callback

echo.init({
  callback: function(element, op) {
    if(op === 'load') {
      element.classList.add('loaded');
    } else {
      element.classList.remove('loaded');
    }
  }
});

.render()

echo.render();

Plugin’s default options:

Name Default Type Description
offset 0 Number|String The offset option allows you to specify how far below, above, to the left, and to the right of the viewport you want Echo to begin loading your images. If you specify 0, Echo will load your image as soon as it is visible in the viewport, if you want to load 1000px below or above the viewport, use 1000.
offsetVertical offset’s value Number|String The offsetVertical option allows you to specify how far above and below the viewport you want Echo to begin loading your images.
offsetHorizontal offset’s value Number|String The offsetHorizontal option allows you to specify how far to the left and right of the viewport you want Echo to begin loading your images.
offsetTop offsetVertical’s value Number|String The offsetTop option allows you to specify how far above the viewport you want Echo to begin loading your images.
offsetBottom offsetVertical’s value Number|String The offsetBottom option allows you to specify how far below the viewport you want Echo to begin loading your images.
offsetLeft offsetVertical’s value Number|String The offsetLeft option allows you to specify how far to left of the viewport you want Echo to begin loading your images.
offsetRight offsetVertical’s value Number|String The offsetRight option allows you to specify how far to the right of the viewport you want Echo to begin loading your images.
throttle 250 Number|String The throttle is managed by an internal function that prevents performance issues from continuous firing of window.onscroll events. Using a throttle will set a small timeout when the user scrolls and will keep throttling until the user stops. The default is 250 milliseconds.
debounce true Boolean By default the throttling function is actually a debounce function so that the checking function is only triggered after a user stops scrolling. To use traditional throttling where it will only check the images every throttle milliseconds, set debounce to false.
unload false Boolean This option will tell echo to unload loaded images once they have scrolled beyond the viewport (including the offset area).
callback Function The callback will be passed the element that has been updated and what the update operation was (ie load or unload). This can be useful if you want to add a class like loaded to the element. Or do some logging.

Leave a comment

Your email address will not be published. Required fields are marked *

STAYUPDATED

Receive all our future posts instantly in your inbox. Enter your email to enroll.