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
Record the installation and configuration method ...
Div basic layout <div class="main"&g...
environment Centos 6.6 MySQL 5.7 Install If the s...
Copy data When copying data remotely, we usually ...
What is an index? An index is a data structure th...
Previously, I introduced several ways to achieve ...
Download and install. First check whether there i...
1. Update the yum source The PostgreSQL version o...
New Questions Come and go in a hurry. It has been...
When configuring proxy_pass in nginx, if you matc...
This article shares the specific code for the WeC...
Everyone must be familiar with table. We often en...
Since Zabbix version 3.0, it has supported encryp...
Table of contents 【Function Background】 [Raw SQL]...
This article uses examples to explain the concept...