初始化

This commit is contained in:
2025-11-26 11:18:26 +08:00
commit 0564b8c1f3
579 changed files with 346253 additions and 0 deletions

View File

@@ -0,0 +1,30 @@
// onload是等所有的资源文件加载完毕以后再绑定事件
window.onload = function () {
setTimeout(lazyload(imgs), 20);
}
//// 获取图片列表即img标签列表
var imgs = document.querySelectorAll('img');
function getTop(e) {
return e.offsetTop;
}
// 懒加载实现
function lazyload(imgs) {
imgs = document.querySelectorAll('img');
for (let i of imgs) {
if ($(i).is(':visible') == true) {
let trueSrc = i.getAttribute("data-src");
if (trueSrc != 'null' && trueSrc != null && trueSrc.indexOf('{{') < 0 && trueSrc.indexOf('}}') < 0) {
$(i).removeAttr("data-src")
i.setAttribute("src", trueSrc);
}
}
}
}
// 滚屏函数
window.onscroll = function () {
//保证每次取到的为最新的
lazyload(imgs);
}