Application of dynamic image loading technology and use case of jquery.lazyload plug-in

Application of dynamic image loading technology and use case of jquery.lazyload plug-in
Application example website http://www.uhuigou.net
Dynamic loading of images is nothing new. Many large websites are using it. The advantages are obvious. It mainly saves traffic (including server and client), provides better user experience, and increases the speed of page opening.
The principle is not complicated. The picture still uses the original img tag, and the src points to a default small picture, such as loading. Then customize an img attribute to save the real picture address. When the user visits the picture location, the src value is changed to the value of the custom attribute through js control.

This function has been made into many plug-ins. The one I use is called jquery.lazyload. If you need it, just download it from my website. This is the only file you need. Of course, you also need jquery.lazyload
The usage is also very simple. Add a data-original attribute to the original img tag to save the real image address. The example is as follows

Copy code
The code is as follows:

<img class="lazy" src="http://bcs.duapp.com/uhuigou/loading.gif" data-original="http://bcs.duapp.com/uhuigou/201306200831326313.jpg" style="width: 100%; display: inline-block;">

Just write this for all the imgs that need to be loaded dynamically. jquery.lazyload only recognizes data-original, style or other attributes. You can write them as needed. Finally, you need to initialize them in the jquery.ready event of the page.

Copy code
The code is as follows:

$(function() {$("img.lazy").lazyload();});

Okay, you’re done!

<<:  How to set a fixed IP address for a VMware virtual machine (graphic tutorial)

>>:  Tutorial on installing GreasyFork js script on mobile phone

Recommend

MySQL 8.0.21 installation and configuration method graphic tutorial

Record the installation and configuration method ...

How to install Mysql5.7 in Centos6

environment Centos 6.6 MySQL 5.7 Install If the s...

How to quickly copy large files under Linux

Copy data When copying data remotely, we usually ...

Various types of MySQL indexes

What is an index? An index is a data structure th...

Ideas for creating wave effects with CSS

Previously, I introduced several ways to achieve ...

How to install MySql in CentOS 8 and allow remote connections

Download and install. First check whether there i...

How to install PostgreSQL and PostGIS using yum on CentOS7

1. Update the yum source The PostgreSQL version o...

Examples of vertical grid and progressive line spacing

New Questions Come and go in a hurry. It has been...

WeChat applet implements countdown for sending SMS verification code

This article shares the specific code for the WeC...

5 ways to achieve the diagonal header effect in the table

Everyone must be familiar with table. We often en...

Zabbix's psk encryption combined with zabbix_get value

Since Zabbix version 3.0, it has supported encryp...

MYSQL Left Join optimization (10 seconds to 20 milliseconds)

Table of contents 【Function Background】 [Raw SQL]...

Detailed explanation of MySQL cursor concepts and usage

This article uses examples to explain the concept...