Commit e4407467 authored by 1045485954@qq.com's avatar 1045485954@qq.com Committed by kl

IE兼容性问题,目前已兼容到IE9

parent 551eeb03
function isInSight(el) {
const bound = el.getBoundingClientRect();
const clientHeight = window.innerHeight;
var bound = el.getBoundingClientRect();
var clientHeight = window.innerHeight;
//只考虑向下滚动加载
//const clientWidth=window.innerWeight;
return bound.top <= clientHeight + 100;
}
let index = 0;
var index = 0;
function checkImgs() {
const imgs = document.querySelectorAll('.my-photo');
for (let i = index; i < imgs.length; i++) {
var imgs = document.querySelectorAll('.my-photo');
for (var i = index; i < imgs.length; i++) {
if (isInSight(imgs[i])) {
loadImg(imgs[i]);
index = i;
......@@ -18,24 +19,47 @@ function checkImgs() {
}
function loadImg(el) {
const source = el.dataset.src;
var source = el.getAttribute("data-src");
el.src = source;
}
// var mustRun = 500
// function throttle(fn, mustRun) {
// var timer = null;
// var previous = null;
// return function() {
// var now = new Date();
// var context = this;
// var args = arguments;
// if (!previous) {
// previous = now;
// }
// var remaining = now - previous;
// if (mustRun && remaining >= mustRun) {
// fn.apply(context, args);
// previous = now;
// }
// }
// }
function throttle(fn, mustRun = 500) {
const timer = null;
let previous = null;
return function() {
const now = new Date();
const context = this;
const args = arguments;
function throttle(fn) {
var timer = null;
var previous = null;
return function () {
var now = new Date();
var context = this;
var args = arguments;
if (!previous) {
previous = now;
}
const remaining = now - previous;
if (mustRun && remaining >= mustRun) {
var remaining = now - previous;
setTimeout(refresh(fn, remaining, context, args, previous, now));
}
}
function refresh(fn, remaining, context, args, previous, now) {
if (remaining >= 500) {
fn.apply(context, args);
previous = now;
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment