~~~
function imgLazyLoad(options) {
var settings = {
Id: $('img'),
threshold: 100,
effectspeed: 0,
effect: "fadeIn"
}
$.extend(settings, options);
var $this = settings.Id;
var timeout = null;
$(window).bind('load resize', loadImg);
$(window).scroll(function() {
if(timeout) {
clearTimeout(timeout);
}
timeout = setTimeout(loadImg ? loadImg : "", 100);
})
function loadImg() {
settings.Id.each(function() {
if(!belowthefold(this)) {
if($(this).is(':visible')) {
$(this).trigger("appear");
}
}
})
}
return $this.each(function(i) {
var self = this;
//$(self).data('t', $(self).offset().top);
if(belowthefold(self)) {
self.loaded = false;
} else {
if($(self).is(':visible')) {
$(self).attr("src", $(self).attr("original"));
self.loaded = true;
}
}
$(self).one("appear",function() {
if(!this.loaded) {
$("<img />").bind("load",function() {
$(self).hide().attr("src", $(self).attr("original"))[settings.effect](settings.effectspeed);
self.loaded = true;
}).attr("src", $(self).attr("original"))
}
})
})
function belowthefold(element) {
var fold = $(window).height() + $(window).scrollTop();
return fold <= $(element).offset().top - settings.threshold;
}
}
imgLazyLoad({
threshold: 0,
effectspeed: 800
})
~~~
- 我的爛筆頭
- 1、常用功能方法整合
- 2、jQuery基本函數
- 3、在頁面中添加圖片
- 4、精度算法
- 5、圖片懶加載
- 6、彈窗拖拽功能
- 7、彈幕功能
- 8、鼠標滾動事件
- 9、獲取頁面相關屬性
- 10、彈窗的三種展現方式
- 11、輪播功能
- 12、獲取唯一標識
- 13、CSS樣式效果
- 14、任意兩點的動態連線
- 15、全新接口功能
- 16、適配兼容
- 17、無刷新頁面更改URL
- 18、定時器的那些事
- 19、關于iframe的常見問題
- 20、設置不同的時間
- 21、關于select-option
- 22、省市級聯
- 23、省市級聯數據
- 24、關于數據傳輸問題
- 25、問題分支
- 那些年我們一起走過的神坑
- 1、關于console的使用
- 2、關于數組
- 1、數組的賦值
- 2、數組的常用方法
- 3、關于移動端的bug
- 4、關于視頻的bug
- 5、那些坑坑洼洼
- 6、關于字符串
- 1、字符串的常用方法
- 頁面布局
- 1、背景固定的滾動頁面
- 心得
- Node.js
- 1、安裝環境
- ThinkPHP 5.1
- 1、訪問格式