How can I load php images with delay and laziness?

Source: Internet
Author: User
My current practice is to replace the image src with a placeholder image, use the data-src attribute to save the actual image address, and then monitor the scroll event of the window, when an image appears on the screen, the value of data-src is assigned to src. However, this approach is not convenient. For example, I don't want... my current practice is to replace the image src with a placeholder image, use the data-src attribute to save the actual image address, and then monitor the scroll event of the window, when an image appears on the screen, the value of data-src is assigned to src.

However, this method is not convenient. For example, if I don't want to delay loading, It is very troublesome to modify the delayed loading articles, for example, I don't need to delay loading when accessing a search engine, and I want to use delayed loading when accessing a user. I don't know how to easily switch between them?

Reply content:

My current practice is to replace the image src with a placeholder image, use the data-src attribute to save the actual image address, and then monitor the scroll event of the window, when an image appears on the screen, the value of data-src is assigned to src.

However, this method is not convenient. For example, if I don't want to delay loading, It is very troublesome to modify the delayed loading articles, for example, I don't need to delay loading when accessing a search engine, and I want to use delayed loading when accessing a user. I don't know how to easily switch between them?

Img = new Image (); img. src = 'HTTP: // www.helloworld.com/test.jpg'; img. onload = function () {var imageContainer = document. getElementById ('imginer iner '); imageContainer. appendChild (img );}

You can store the original data in the database, that issrcBefore the output, add the filter and replace itdata-src. In this way, you only need to delete the filter call to restore the original state.

function add_lazy_load_filter($html) {    return preg_replace("//is", "", $html);}

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.