diff --git a/config.json b/config.json index 733795c..e673254 100644 --- a/config.json +++ b/config.json @@ -20,5 +20,5 @@ "needComment":0, "indexScript":"", "bottomText":"❤️ 转载文章请注明出处,谢谢!❤️", - "script":"" + "script":"" } diff --git a/docs/assets/lazyload.js b/docs/assets/lazyload.js new file mode 100644 index 0000000..914481e --- /dev/null +++ b/docs/assets/lazyload.js @@ -0,0 +1,25 @@ + // lazyload.js + document.addEventListener('DOMContentLoaded', () => { + const images = document.querySelectorAll('img[data-src]'); + + const lazyLoad = target => { + const io = new IntersectionObserver((entries, observer) => { + entries.forEach(entry => { + if (entry.isIntersecting) { + const img = entry.target; + img.src = img.dataset.src; + img.onload = () => { + img.classList.add('loaded'); + }; + observer.disconnect(); + } + }); + }); + + io.observe(target); + }; + + images.forEach(img => { + lazyLoad(img); + }); + }); \ No newline at end of file