feat: scroll to top on page switch

This commit is contained in:
afn 2023-03-26 16:03:52 -04:00
parent 943ced0513
commit c03344b04c

View File

@ -83,6 +83,17 @@
logos[j] = k; logos[j] = k;
} }
function preloadImage(url: string) {
let img = new Image();
img.src = url;
}
logos.forEach((variants) => {
variants.forEach((variant) =>
preloadImage(variant.optimized_direct_url ?? variant.logo_direct_url)
);
});
// min is the lowest index of the logos on a page, max is the highest index // min is the lowest index of the logos on a page, max is the highest index
// max will be determined based on min and the amount of logos we want on each page (4) // max will be determined based on min and the amount of logos we want on each page (4)
min = currentPage * logoAmount; min = currentPage * logoAmount;
@ -93,7 +104,7 @@
logos = logos; logos = logos;
if (location.hash !== '') { if (location.hash !== '') {
botToken = location.hash.substring(1) botToken = location.hash.substring(1);
try { try {
await exchange_token(location.hash.substring(1)); await exchange_token(location.hash.substring(1));
} catch (err) { } catch (err) {
@ -110,32 +121,19 @@
} }
}); });
function preloadImage(url: string) {
var img = new Image();
img.src = url;
}
function previousPage() { function previousPage() {
if (currentPage <= 0) return null; if (currentPage <= 0) return null;
currentPage--; currentPage--;
submit = false; submit = false;
transitionDirection = -5; transitionDirection = -5;
window.scrollTo({ top: 0, left: 0, behavior: 'smooth' });
} }
function nextPage() { function nextPage() {
let nextPage = currentPage + 1;
if (currentPage >= logoPages || submit) return null; if (currentPage >= logoPages || submit) return null;
currentPage++; currentPage++;
const nextMin = nextPage * logoAmount;
const nextMax = nextMin + logoAmount;
logos.slice(nextMin, nextMax).forEach((variants) => {
variants.forEach((variant) =>
preloadImage(variant.optimized_direct_url ?? variant.logo_direct_url)
);
});
transitionDirection = 5; transitionDirection = 5;
window.scrollTo({ top: 0, left: 0, behavior: 'smooth' });
} }
function submitSelection() { function submitSelection() {