Skip to content

Commit

Permalink
Fix icons hover not updating on scroll in Technos section on Safari (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
WarningImHack3r authored Nov 16, 2023
1 parent d8c247a commit 65d4386
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "emerald-website",
"version": "1.0.4",
"version": "1.0.5",
"private": true,
"scripts": {
"dev": "vite",
Expand Down
28 changes: 14 additions & 14 deletions src/routes/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -276,26 +276,26 @@
interval = setInterval(autoScroll, DELAY);
});
// Add listeners to the icons to start/stop the interval on hover
[...technoIcons.children].forEach(icon => {
icon.addEventListener("mouseenter", () => {
clearInterval(interval);
});
icon.addEventListener("mouseleave", () => {
interval = setInterval(autoScroll, DELAY);
});
});
// Scroll handler to update the hovered icon depending on
// the card we scrolled to
technoCards.addEventListener("scrollend", () => {
if (!technoCards) return; // fix "scrollLeft not found on undefined"?
function onTechnoCardsScrollEnd() {
if (!technoCards) return; // fix "scrollLeft not found on undefined"
const scrollDistance = technoCards.scrollLeft;
const containerWidth = technoCards.clientWidth;
currentCard = Math.round(scrollDistance / containerWidth);
hoverIcon(currentCard);
});
}
if ("onscrollend" in window) {
technoCards.addEventListener("scrollend", onTechnoCardsScrollEnd);
} else {
// Safari fallback
let i: ReturnType<typeof setTimeout>;
technoCards.addEventListener("scroll", () => {
clearTimeout(i);
i = setTimeout(onTechnoCardsScrollEnd, 100);
});
}
// On destroy, clear the interval
return () => clearInterval(interval);
Expand Down

0 comments on commit 65d4386

Please sign in to comment.