mirror of
https://github.com/Derpy-Leggies/OnlyLegs.git
synced 2025-06-29 03:26:16 +00:00
Check for webp image support
This commit is contained in:
parent
ad44f0119e
commit
ce64821500
1 changed files with 13 additions and 1 deletions
|
@ -1,3 +1,11 @@
|
||||||
|
let webpSupport = false;
|
||||||
|
try {
|
||||||
|
new Image().src = 'data:image/webp;base64,UklGRiQAAABXRUJQVlA4IBgAAAAwAQCdASoBAAEAAwA0JaQAA3AA/vuUAAA=';
|
||||||
|
webpSupport = true;
|
||||||
|
} catch (e) {
|
||||||
|
webpSupport = false;
|
||||||
|
}
|
||||||
|
|
||||||
// fade in images
|
// fade in images
|
||||||
function imgFade(obj, time = 250) {
|
function imgFade(obj, time = 250) {
|
||||||
obj.style.transition = `opacity ${time}ms`;
|
obj.style.transition = `opacity ${time}ms`;
|
||||||
|
@ -10,7 +18,11 @@ function loadOnView() {
|
||||||
for (let i = 0; i < lazyLoad.length; i++) {
|
for (let i = 0; i < lazyLoad.length; i++) {
|
||||||
let image = lazyLoad[i];
|
let image = lazyLoad[i];
|
||||||
if (image.getBoundingClientRect().top < window.innerHeight && image.getBoundingClientRect().bottom > 0) {
|
if (image.getBoundingClientRect().top < window.innerHeight && image.getBoundingClientRect().bottom > 0) {
|
||||||
if (!image.src) { image.src = image.getAttribute('data-src') }
|
if (!image.src && webpSupport) {
|
||||||
|
image.src = image.getAttribute('data-src') + '&e=webp'
|
||||||
|
} else if (!image.src) {
|
||||||
|
image.src = image.getAttribute('data-src')
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue