The
looks like this:
/** * Piclazyload picture delay loading, including background image * $ (IMG). Piclazyload ({...})
* Data-original Pre-loading picture address * Alon/;(function ($) {$.fn.imglazyload = function (settings) {var $this = $ (this),
_winscrolltop = 0, _winheight = $ (window). Height (); Settings = $.extend ({threshold:0,//Advance height load placeholder: ' Data:image/png;base64,ivborw0kggoaaaansuheugaaaaea aaabcayaaaaffcsjaaaaaxnsr0iars4c6qaaaarnqu1baacxjwv8yquaaaajcehzcwaadsqaaa7eazurdhsaaaansurbvbhxyzh8+pb/ AAFFA0NNPUCLAAAAAELFTKSUQMCC ', Callback:function () {}}, settings| |
{});
Execute lazy Load picture lazyloadpic (); Scroll trigger for $ (window). On (' scroll ', function () {_winscrolltop = Document.documentElement.scrollTop | | window.pageyof Fset | |
Document.body.scrollTop;
Lazyloadpic ();
});
Lazy load Picture function lazyloadpic () {$this. each (function () {var $self = $ (this);
if ($self. Is (' img ')) {if ($self. attr (' data-original ')) {var _offsettop = $self. Offset (). if ((_offsettop-settings.threshold) <= (_winheight + _winscrolltop)) {$self. attr (' src ', $self. A
TTR (' data-original '));
$self. Removeattr (' data-original ');
$self. Removeclass (' loadh ');
Settings.callback ($self); }}else{if ($self. attr (' data-original ')) {//default placeholder picture if ($self. css (' Background-imag
E ' = = ' None ') {$self. css (' background-image ', ' url (' +settings.placeholder+ ') ');
var _offsettop = $self. Offset (). Top; if ((_offsettop-settings.threshold) <= (_winheight + _winscrolltop)) {$self. css (' background-image ', ' url (
' + $self. attr (' data-original ') + ');
$self. Removeattr (' data-original ');
Settings.callback ($self);
}
}
}
}); }}) (Zepto);
Call
$ (' img '). Imglazyload ({callback:function (data) {
})
The above piclazyload implementation of the picture delay loading (including background picture) is a small series to share all the content, hope to give you a reference, but also hope that we support the cloud-dwelling community.