移动端懒加载js模块
function load(){
// 获取页面已经滚动的高度
var scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
// 获取当前屏幕的高度
var clientHeight = document.documentElement.clientHeight || document.body.clientHeight;
// console.log(scrollTop);
// console.log(clientHeight);
//获取图片的类名
var image = document.getElementsByClassName("images");
// 循环遍历
for(var img of image){
// console.log(img);
//判断 如果图片.offsetop<= 滚动高+屏幕高
if((img.scrollTop + 200 <= (scrollTop + clientHeight))){
var realSrc = img.getAttribute('data-realSrc');
// console.log(realSrc);
img.src = realSrc;
}
}
}
window.onload = load;
window.onscroll = load;
浙公网安备 33010602011771号