侧边栏壁纸
博主头像
落叶人生博主等级

走进秋风,寻找秋天的落叶

  • 累计撰写 130562 篇文章
  • 累计创建 28 个标签
  • 累计收到 9 条评论
标签搜索

目 录CONTENT

文章目录

移动端图片懒加载

2024-05-08 星期三 / 0 评论 / 0 点赞 / 60 阅读 / 977 字

//依赖于jquery,图片url存放在data-lazysrc属性中 mgLazyLoad = function (t, e) { var n = this; t || (t = "data-laz

//依赖于jquery,图片url存放在data-lazysrc属性中 mgLazyLoad = function (t, e) { var n = this; t || (t = "data-lazysrc"), n.imgNodeAttr = t, e || (e = $(window)), n.$pageScroller = e, n.mobileHeight = $(window).height(), n.mobileWidth = $(window).width(), n.loadCurentScreen(), e.on("scroll", function () { n.loadCurentScreen() }) }; ImgLazyLoad.prototype = { loadCurentScreen: function () { var t, e, n = this, i = $("body").scrollTop(), r = $("img[" + n.imgNodeAttr + "]"); $(r).each(function () { var r = $(this).offset(); t = r.top - i, e = r.left, t < n.mobileHeight && t > 0 && n.replaceImgSrc($(this)) }) }, replaceImgSrc: function (t) { var e = $(t).attr("data-lazysrc"); e && $(t).attr("src", e).removeAttr("data-lazysrc") } }, ImgLazyLoad.init = function (t, e) { return new ImgLazyLoad(t, e) };

广告 广告

评论区