From e4407467dd1847318b362d02262f73ef02f561d5 Mon Sep 17 00:00:00 2001 From: "1045485954@qq.com" <1045485954@qq.com> Date: Wed, 17 Jul 2019 07:21:43 +0800 Subject: [PATCH] =?UTF-8?q?IE=E5=85=BC=E5=AE=B9=E6=80=A7=E9=97=AE=E9=A2=98?= =?UTF-8?q?=EF=BC=8C=E7=9B=AE=E5=89=8D=E5=B7=B2=E5=85=BC=E5=AE=B9=E5=88=B0?= =?UTF-8?q?IE9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/resources/static/js/lazyload.js | 82 ++++++++++++------- 1 file changed, 53 insertions(+), 29 deletions(-) diff --git a/jodconverter-web/src/main/resources/static/js/lazyload.js b/jodconverter-web/src/main/resources/static/js/lazyload.js index 8376ed45..5beff487 100644 --- a/jodconverter-web/src/main/resources/static/js/lazyload.js +++ b/jodconverter-web/src/main/resources/static/js/lazyload.js @@ -1,41 +1,65 @@ function isInSight(el) { - const bound = el.getBoundingClientRect(); - const clientHeight = window.innerHeight; - //只考虑向下滚动加载 - //const clientWidth=window.innerWeight; - return bound.top <= clientHeight + 100; + 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++) { - if (isInSight(imgs[i])) { - loadImg(imgs[i]); - index = i; + var imgs = document.querySelectorAll('.my-photo'); + for (var i = index; i < imgs.length; i++) { + if (isInSight(imgs[i])) { + loadImg(imgs[i]); + index = i; + } } - } } function loadImg(el) { - const source = el.dataset.src; - el.src = source; + 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) { + 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; + setTimeout(refresh(fn, remaining, 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; - if (!previous) { - previous = now; +function refresh(fn, remaining, context, args, previous, now) { + if (remaining >= 500) { + fn.apply(context, args); + previous = now; } - const remaining = now - previous; - if (mustRun && remaining >= mustRun) { - fn.apply(context, args); - previous = now; - } - } }