feat: fade in lazy loaded images
This commit is contained in:
parent
c7914b3d30
commit
cac3856de4
@ -19,6 +19,8 @@
|
|||||||
<meta name="msapplication-TileColor" content="#da532c">
|
<meta name="msapplication-TileColor" content="#da532c">
|
||||||
<meta name="theme-color" content="#ffffff">
|
<meta name="theme-color" content="#ffffff">
|
||||||
|
|
||||||
|
<script src="/lazy.js"/>
|
||||||
|
|
||||||
<body data-sveltekit-preload-data="hover">
|
<body data-sveltekit-preload-data="hover">
|
||||||
<div style="display: contents">%sveltekit.body%</div>
|
<div style="display: contents">%sveltekit.body%</div>
|
||||||
</body>
|
</body>
|
||||||
|
@ -15,8 +15,17 @@ html, body {
|
|||||||
background-size: 80%;
|
background-size: 80%;
|
||||||
}
|
}
|
||||||
|
|
||||||
html {
|
html {
|
||||||
background: black;
|
background: black;
|
||||||
background-image: url(/pattern_b.jpg);
|
background-image: url(/pattern_b.jpg);
|
||||||
backdrop-filter: brightness(0.3);
|
backdrop-filter: brightness(0.3);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
img.lazy-image {
|
||||||
|
opacity: 0;
|
||||||
|
transition: opacity 0.3s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
img.lazy-image.loaded {
|
||||||
|
opacity: 1;
|
||||||
|
}
|
||||||
|
13
static/lazy.js
Normal file
13
static/lazy.js
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
window.onload = function(){
|
||||||
|
|
||||||
|
var lazyImages = [...document.querySelectorAll("img[loading='lazy']")];
|
||||||
|
|
||||||
|
for (let i = 0; i < lazyImages.length; i++) {
|
||||||
|
var element = lazyImages[i];
|
||||||
|
element.classList.add("lazy-image")
|
||||||
|
element.addEventListener("load", function(){
|
||||||
|
element.classList.add("loaded");
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user