mirror of
https://codeberg.org/Hyperpipe/Hyperpipe
synced 2025-06-29 05:28:00 +02:00
Playlists, Play Next, Code Refactor
This commit is contained in:
parent
5486be7613
commit
51c56abe16
17 changed files with 664 additions and 204 deletions
33
src/scripts/util.js
Normal file
33
src/scripts/util.js
Normal file
|
@ -0,0 +1,33 @@
|
|||
export function usePrefs(key) {
|
||||
if (localStorage) {
|
||||
if (localStorage.get(key)) return true
|
||||
else return false
|
||||
} else return false
|
||||
}
|
||||
|
||||
export function useLazyLoad() {
|
||||
let lazyElems;
|
||||
|
||||
if ('IntersectionObserver' in window) {
|
||||
lazyElems = document.querySelectorAll('.bg-img:not(.lazy)');
|
||||
|
||||
let imgObs = new IntersectionObserver((elems, obs) => {
|
||||
elems.forEach((elem) => {
|
||||
setTimeout(() => {
|
||||
if (elem.isIntersecting) {
|
||||
let ele = elem.target;
|
||||
|
||||
ele.classList.add('lazy');
|
||||
imgObs.unobserve(ele);
|
||||
}
|
||||
}, 20);
|
||||
});
|
||||
});
|
||||
|
||||
lazyElems.forEach((img) => {
|
||||
imgObs.observe(img);
|
||||
});
|
||||
} else {
|
||||
console.log('Failed');
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue