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 issrc
Before 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);}