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
MySQL startup error Before installing MySQL on Wi...
Table of contents Overview Using mapped types to ...
<br />"There are no ugly women in the w...
Preface If you want to count the source of websit...
Preface Histogram is a basic statistical informat...
There are many special symbols used in mathematic...
The previous article introduced the MySql multi-c...
The solution to the problem that Ubuntu 18.04 in ...
Linux system version: CentOS7.4 MySQL version: 5....
<br />This site’s original content, please i...
Table of contents From father to son: Son to Fath...
This article shares the specific code of javascri...
This article example shares the specific code of ...
Table of contents Preface 1. The significance of ...
Table of contents Shallow copy Deep Copy Replenis...