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
Preface The role of process management: Determine...
1. Download 1. Download the installation package ...
Nginx can generally be used for seven-layer load ...
HTML is made up of tags and attributes, which are...
Today is another very practical case. Just hearin...
1. Build the basic image of jmeter The Dockerfile...
The multi-site feature of WordPress allows you to...
My mysql version is MYSQL V5.7.9, please use the ...
Recently a friend asked me if I have ever played ...
Experimental environment • A minimally installed ...
Table of contents Table/index.js Table/model/inde...
The drag function is mainly used to allow users t...
Table of contents Preface 1. What variables are p...
1. Abnormal performance of Docker startup: 1. The...
Table of contents 1. Write Webshell into outfile ...