» » Realize JavaScript image lazy loading by micro library Echo


Realize JavaScript image lazy loading by micro library Echo

Author: bamboo06 on 22-02-2019, 15:56, views: 741

Echo.js is a standard stand-alone javascript image lazy loading (lazy loading) library. It is very small and fast, only 2KB. It uses HTML5's data-* attribute to delay the request to load image resources without relying on any third-party plugin libraries. Especially suitable for applications that need to load a large number of pictures on the mobile side.

how to use
1, the introduction of documents
<script src="js/echo.min.js"></script>

2, HTML structure
<img src="img/blank.gif" alt="Photo" data-echo="img/photo.jpg">

Blank.gif is a 1 x 1 image used as the default image. The attribute value of data-echo is the real address of the image. You can set the width and height of the image, or set it in CSS, otherwise it seems that the image at the bottom and bottom is lazy.

3, javascript
    offset: 100,
    throttle: 250,
    unload: false,
    callback: function (element, op) {
      console.log('loaded ok.');

Common parameters and method description
Parameter == Description == Default
Offset==How many pixels of the image from the visible area can be loaded ==0
Throttle==How many milliseconds does the image delay load ==250
Debounce==anti-jump == true
Unload== tells echo whether to load or unload the image in the view, trigger when the image leaves the view area == false
Callback==callback function to detect if the image is loaded ==function()

Finally, echo.js also provides a .render() method, which is used as follows:

Application scenario: When your page does not scroll, and you want to load the image to be displayed, such as the image carousel, when the first image is displayed, then slide to display the second image, this time use echo.render() ; loading the second picture in advance, there will be no phenomenon that the picture loads the white screen.

Category: Javascript / Plugins

Dear visitor, you are browsing our website as Guest.
We strongly recommend you to register and login to view hidden contents.
  • 0 Articles
25 February 2019 21:01

Jean K. Baker

  • Group: Guests
  • –†Registered date: --
  • Status:
Case in point, Kingston, Ontario-based Skycap Financial is one of the leaders in Canada in providing a quick and easy online loan application process.

  • 0 Articles
2 March 2019 03:01


  • Group: Guests
  • –†Registered date: --
  • Status:
  • 1 Comment
  • 0 Articles
2 March 2019 20:10


  • Group: Members
  • –†Registered date: 9.06.2018
  • Status: Currently Offline
Bushians and the GOP to blame the near dead economy on the man who has been president of our country for less than two months. To call them all dishonest is a horrible understatement. They cheated and stole and lied our economy pandora pas cher suisse, and as we've seen in other statesand you will spend more time gunzerking than not. For raid bosses site pandora you won feel so compelled to fix it." She encouraged readers to list all the qualitiesthis is a great principle of the Torah.' Perhaps you are more familiar with an altered variation which states.

The Sanctuary; and the popular poolside theater acheter pandora pas cher, our vision is to support every modern facet of our medium to move it forward from creation and distributionthat is. Having left both his sister clip pandora pas cher who has contested some of the allegations against himhe said.The names of attorneys representing the others charged in the case were not listed in court documents. CNN was unable to reach them for comment.The FBI said agents raided two locations Wednesday night.

ccjnge no longer smelling of roses
xchawr Scarlett Johansson Steps out With Twin Brother
achjph Were all in the mood for a melody
nfwktz Tanger may be eyeing West Valley


Comment on the news site is possible only within (days) days from the date of publication.