Lazyload.js reduces the load of images
<img data-orignal="xxxx.png" src="img/grey.gif" >
//Inert loading of pictures in the text var imgs = $(".wrapper-lg img"); for (var i = 0; i < imgs.length; i ++) { var srcvalue = $(imgs[i]).attr("src"); $(imgs[i]).attr("data-original",srcvalue); $(imgs[i]).attr("src","<?php $this->options->themeUrl("img/grey.gif") ?>"); }
<? php //Relevant processing of image delay loading, replace src with data original, and add placeholder $echo = ob_get_contents(); // Get buffer content ob_clean(); // Clear buffer content, not output to the page $placeholder = "img/grey.gif"; // Placeholder Picture $preg = "/<img (.*)src(.*) \/>/i"; // Match picture regularly $replaced = '<img \\1src="'.$placeholder.'" data-original\\2 />'; print preg_replace($preg, $replaced, $echo); // Rewritten buffer ob_end_flush(); // Enter the buffer into the page and close the buffer ?>
$("img").lazyload();
<img src="" (other html code)/>
-
Load special effects: the pictures will be displayed in fading mode (see the official documents for more special effects)
$("img").lazyload({ effect : "fadeIn" });
-
Trigger loading method: you can select to click the picture to display the content
$("img").lazyload({ event : "click" });