changed scrolling code a little bit

This commit is contained in:
corgifist 2025-07-27 23:46:48 +03:00
parent 0710981de7
commit fd21a73620
2 changed files with 7 additions and 3 deletions

View File

@ -11,7 +11,9 @@ export const ScrollFadingTitle = (props: ComponentProps<"div">) => {
useEffect(() => { useEffect(() => {
const handleScroll = () => { const handleScroll = () => {
if (!elementRef.current) return; if (!elementRef.current) return;
const opacity = easeFade(1 - (window.scrollY / ( window.innerHeight / 20))); const opacity = easeFade(
Math.max(0, Math.min(1, 1 - (window.scrollY / (window.innerHeight / 20))))
);
elementRef.current.style.opacity = `${opacity}`; elementRef.current.style.opacity = `${opacity}`;
}; };

View File

@ -19,12 +19,14 @@ export const SidebarTriggerAdjustable = (props: ComponentProps<"div">) => {
return; return;
} }
const triggerDiv = triggerElement as HTMLDivElement; const triggerDiv = triggerElement as HTMLDivElement;
const slideAmount = easeSlide(Math.max(0, Math.min(1, window.scrollY / (window.innerHeight / 20)))); const slideAmount = easeSlide(
Math.max(0, Math.min(1, window.scrollY / (window.innerHeight / 20)))
);
triggerDiv.style.marginLeft = `calc(var(--spacing) * ${12 * slideAmount})`; triggerDiv.style.marginLeft = `calc(var(--spacing) * ${12 * slideAmount})`;
triggerDiv.style.paddingTop = `calc(var(--spacing) * ${(isMobile ? 1 : 3) * slideAmount})`; triggerDiv.style.paddingTop = `calc(var(--spacing) * ${(isMobile ? 1 : 3) * slideAmount})`;
}; };
window.addEventListener('scroll', handleScroll); window.addEventListener('scroll', handleScroll, {passive: true});
return () => { return () => {
window.removeEventListener('scroll', handleScroll); window.removeEventListener('scroll', handleScroll);