- //懒加载代码
- function _LazyImg(con) {
- var li = con;//con.find(".service-item");
- var win = $(window);
- var wh = win.height();
- var n = 0;
- var loadimg = function() {
- var st = win.scrollTop() + wh;
- li.each(function() {
- var t = $(this);
- var ot = t.offset().top;
- if (st >= ot && !t.attr("loaded")) {
- n++;
- t.attr("loaded", true);
- t.find("img.lazyimg").each(function() {
- var img = $(this);
- var ori = img.attr("original");
- img.hide().attr("src", ori).fadeIn();
- });
- }
- });
- if (n == li.length) {
- win.unbind("scroll", loadimg);
- }
- };
- win.bind("scroll", loadimg);
- loadimg();
- }
- //该片段来自于http://www.codesnippet.cn/detail/181120137233.html
来源: http://www.codesnippet.cn/detail/181120137233.html