Image delay loading plug-in based on jQuery or Zepto
Implementation principle
use
/*! * Lazy Load - jQuery plugin for lazy loading images * * Copyright (c) 2007-2015 Mika Tuupola * * Licensed under the MIT license: * http://www.opensource.org/licenses/mit-license.php * * Project home: * http://www.appelsiini.net/projects/lazyload * * Version: 1.9.7 * */
/*! * An jQuery | zepto plugin for lazy loading images. * author -> jieyou * see https://github.com/jieyou/lazyload * use some tuupola's code https://github.com/tuupola/jquery_lazyload (BSD) * use component's throttle https://github.com/component/throttle (MIT) */
lazyload.js
<script src="jQuery.js"></script><script src="lazyload.min.js"></script>
<!-- Lazyload.js default lazy loading original image attribute is data original --><img class="lazy" src="loading. png" data original="img/example. jpg"> $(".lazy").lazyload();
Default:
defaultOptions = { Threshold: 0,//How many images are loaded in advance, in px failure_limit : 0, Event: 'scroll',//Trigger event Effect: 'show',//effect Effect_params: null,//the parameter array of effect Container: w,//Use the container. The default is window Data_attribute: 'original',//can be changed to src, which corresponds to the data src attribute data_srcset_attribute : 'original-srcset', skip_invisible : true, appear : emptyFn, load : emptyFn, Vertical_only: false,//used in vertical scrolling pages check_appear_throttle_time : 300, url_rewriter_fn : emptyFn, no_fake_img_loader : false, placeholder_data_img : 'data:image/png; base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB/AAffA0nNPuCLAAAAAElFTkSuQmCC', // for IE6\7 that does not support data image placeholder_real_img : ' http://ditu.baidu.cn/yyfm/lazyload/0.0.1/img/placeholder.png ' //Todo: use global to configure some attributes, instead of configuring} YAML copy full screen in $(selector). lazyload ({}) every time }
Example:
$(function() { $(".lazy").lazyload({ Effect: "fadeIn",//effect Data_attribute: 'src',//can be changed to src, which corresponds to the data src attribute Event: 'scroll',//default value Container: $(". content"),//It is generally unnecessary to specify, that is, window. Must be specified in the sui frame }); });