jquery-lazyload延迟加载图片 及 加载顺序 bug 修复 jquery-lazyload延迟加载图片

代码修改片段

function update() {

var counter = 0;

/**fix by weiyj start***/

elements.sort(function(a,b){

var value=$(a).offset().top-$(b).offset().top;

if(value==0){

value=$(a).offset().left-$(b).offset().left;

}

return value;

});

/**fix by weiyj end ***/


下载地址:https://github.com/tuupola/jquery_lazyload
用法:
头部引用
<script src="jquery.js" type="text/javascript"></script> <script src="jquery.lazyload.js" type="text/javascript"></script>
body引用
修改 HTML 代码中需要延迟加载的 IMG 标签
<!-- 


将真实图片地址写在 data-original 属性中,而 src 属性中的图片换成占位符的图片(例如 1x1 像素的灰色图片或者 loading 的 gif 图片)


添加 class="lazy" 用于区别哪些图片需要延时加载,当然你也可以换成别的关键词,修改的同时记得修改调用时的 jQuery 选择器


添加 width 和 height 属性有助于在图片未加载时占满所需要的空间


-->


<img class="lazy" src="grey.gif" data-original="example.jpg" width="640" heigh="480">

调用
$("img.lazy").lazyload();

参数说明

名称默认值说明
containerwindow父容器。延迟加载父容器中的图片。 [Demo1][Demo2]
event'scroll'触发加载的事件 [Demo]
effect'show'加载使用的动画效果,如 show, fadeIn, slideDown 等 jQuery 自带的效果,或者自定义动画。 [Demo]
effectspeedundefined动画时间。作为 effect 的参数使用:effect(effectspeed)
data_attribute'original'真实图片地址的 data 属性后缀
threshold0灵敏度。默认为 0 表示当图片出现在显示区域中的立即加载显示;设为整数表示图片距离 x 像素进入显示区域时进行加载;设为负数表示图片进入显示区域 x 像素时进行加载。
failure_limit0容差范围。页面滚动时,Lazy Load 会遍历延迟加载的图片,检查是否在显示区域内,默认找到第 1 张不可见的图片时,就终止遍历。因为 Lazy Load 认为图片的排序是与 HTML 中的代码中的排序相同,但是也可能会出现例外,通过该值来扩大容差范围。
skip_invisibletrue跳过隐藏的图片。图片不可见时(如 display:none),不强制加载。
appearnull图片加载时的事件 (Function),有 2 个参数:elements_left(未加载的图片数量)、settings(lazyload 的参数)。[Demo](参考 DEMO 的源代码)
loadnull图片加载后的事件 (Function),有 2 个参数,同 appear 。[Demo](参考 DEMO 的源代码)

在容器中使用:
#container {
    height: 600px;
    overflow: scroll;
}
$("img.lazy").lazyload({
     container: $("#container")
});
实例:

<!DOCTYPE html>

<html >

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

<meta charset="utf-8">

<title>Lazy Load Enabled With AJAX Content</title>

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<style type="text/css">

.container img {

margin-bottom: 10px;

}

#container {

width: 800px;

overflow: scroll;

}

#inner_container {

width: 4750px;

}

</style>

</head>

<body>

<div >

</div>

</div>

<script src="jquery-1.11.3.min.js"></script>

<script src="jquery.lazyload.js?v=1.9.7"></script>

<script>

$(function() {

$("img.lazy").lazyload({

effect : "fadeIn",

container: $("#container"),

threshold : -200

});

});

</script>

</body>

</html>


下载地址:https://github.com/tuupola/jquery_lazyload
用法:
头部引用
<script src="jquery.js" type="text/javascript"></script> <script src="jquery.lazyload.js" type="text/javascript"></script>
body引用
修改 HTML 代码中需要延迟加载的 IMG 标签
<!-- 


将真实图片地址写在 data-original 属性中,而 src 属性中的图片换成占位符的图片(例如 1x1 像素的灰色图片或者 loading 的 gif 图片)


添加 class="lazy" 用于区别哪些图片需要延时加载,当然你也可以换成别的关键词,修改的同时记得修改调用时的 jQuery 选择器


添加 width 和 height 属性有助于在图片未加载时占满所需要的空间


-->


<img class="lazy" src="grey.gif" data-original="example.jpg" width="640" heigh="480">

调用
$("img.lazy").lazyload();

参数说明

名称默认值说明
containerwindow父容器。延迟加载父容器中的图片。 [Demo1][Demo2]
event'scroll'触发加载的事件 [Demo]
effect'show'加载使用的动画效果,如 show, fadeIn, slideDown 等 jQuery 自带的效果,或者自定义动画。 [Demo]
effectspeedundefined动画时间。作为 effect 的参数使用:effect(effectspeed)
data_attribute'original'真实图片地址的 data 属性后缀
threshold0灵敏度。默认为 0 表示当图片出现在显示区域中的立即加载显示;设为整数表示图片距离 x 像素进入显示区域时进行加载;设为负数表示图片进入显示区域 x 像素时进行加载。
failure_limit0容差范围。页面滚动时,Lazy Load 会遍历延迟加载的图片,检查是否在显示区域内,默认找到第 1 张不可见的图片时,就终止遍历。因为 Lazy Load 认为图片的排序是与 HTML 中的代码中的排序相同,但是也可能会出现例外,通过该值来扩大容差范围。
skip_invisibletrue跳过隐藏的图片。图片不可见时(如 display:none),不强制加载。
appearnull图片加载时的事件 (Function),有 2 个参数:elements_left(未加载的图片数量)、settings(lazyload 的参数)。[Demo](参考 DEMO 的源代码)
loadnull图片加载后的事件 (Function),有 2 个参数,同 appear 。[Demo](参考 DEMO 的源代码)

在容器中使用:
#container {
    height: 600px;
    overflow: scroll;
}
$("img.lazy").lazyload({
     container: $("#container")
});
实例:

<!DOCTYPE html>

<html >

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

<meta charset="utf-8">

<title>Lazy Load Enabled With AJAX Content</title>

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<style type="text/css">

.container img {

margin-bottom: 10px;

}

#container {

width: 800px;

overflow: scroll;

}

#inner_container {

width: 4750px;

}

</style>

</head>

<body>

<div >

</div>

</div>

<script src="jquery-1.11.3.min.js"></script>

<script src="jquery.lazyload.js?v=1.9.7"></script>

<script>

$(function() {

$("img.lazy").lazyload({

effect : "fadeIn",

container: $("#container"),

threshold : -200

});

});

</script>

</body>

</html>