mirror of
https://gitee.com/kekingcn/file-online-preview.git
synced 2025-09-19 18:22:20 +08:00
word、ppt文档新增图片预览模式
This commit is contained in:
41
jodconverter-web/src/main/resources/static/js/lazyload.js
Normal file
41
jodconverter-web/src/main/resources/static/js/lazyload.js
Normal file
@@ -0,0 +1,41 @@
|
||||
function isInSight(el) {
|
||||
const bound = el.getBoundingClientRect();
|
||||
const clientHeight = window.innerHeight;
|
||||
//只考虑向下滚动加载
|
||||
//const clientWidth=window.innerWeight;
|
||||
return bound.top <= clientHeight + 100;
|
||||
}
|
||||
|
||||
let 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function loadImg(el) {
|
||||
const source = el.dataset.src;
|
||||
el.src = source;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
const remaining = now - previous;
|
||||
if (mustRun && remaining >= mustRun) {
|
||||
fn.apply(context, args);
|
||||
previous = now;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user