_javascript technique of picture lazy loading based on javascript

Source: Internet
Author: User

I. Definition

Picture delay loading is also known as lazy loading, loading some pictures when the picture is delayed or meets certain conditions, and is usually used for pages with more pictures. You can reduce the number of requests or delay requests to optimize performance.

Ii. form of presentation

"1" delay loading, using settimeout or setinterval load delay, if the user left before loading, naturally will not be loaded.
The "2" condition loads, meets certain conditions, or triggers certain conditions before asynchronous loading begins.
"3" visual area loading, only load the user can see the area, the main monitoring scroll bar to achieve, generally close to the user to see the bottom when the load started, so that users can be pulled down when the picture just connected, there will not be too long pause.

Iii. Basic Steps

The pictures on the "1" page are all set to the same picture
"2" adds data-original = "Img/test.jpg" attribute to the picture, saving the real address of the picture
"3" when certain conditions are triggered, the SRC attribute of the picture of the area is automatically changed to the real address

Four, the application

1, click the button to show the picture

<! DOCTYPE html>
 
 

2, the visual area display picture

<!
DOCTYPE html>  

The above is the entire content of this article, I hope to help you learn, the smooth implementation of JavaScript pictures lazy loading.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.