fix(feat): add locales and refine responsive landing page UI
This commit is contained in:
@@ -31,6 +31,42 @@ const {
|
||||
(() => {
|
||||
const header = document.getElementById('site-header');
|
||||
const getOffset = () => header ? header.offsetHeight : 0;
|
||||
let activeScrollAnimation = 0;
|
||||
|
||||
const easeInCubic = (t: number) => t * t * t;
|
||||
|
||||
const animateScrollTo = (targetTop: number) => {
|
||||
const startTop = window.scrollY;
|
||||
const distance = targetTop - startTop;
|
||||
|
||||
if (window.matchMedia('(prefers-reduced-motion: reduce)').matches) {
|
||||
window.scrollTo(0, targetTop);
|
||||
return;
|
||||
}
|
||||
|
||||
if (activeScrollAnimation) {
|
||||
cancelAnimationFrame(activeScrollAnimation);
|
||||
}
|
||||
|
||||
const duration = Math.min(1300, Math.max(650, Math.abs(distance) * 0.7));
|
||||
const startTime = performance.now();
|
||||
|
||||
const step = (now: number) => {
|
||||
const elapsed = now - startTime;
|
||||
const progress = Math.min(elapsed / duration, 1);
|
||||
const easedProgress = easeInCubic(progress);
|
||||
|
||||
window.scrollTo(0, startTop + distance * easedProgress);
|
||||
|
||||
if (progress < 1) {
|
||||
activeScrollAnimation = requestAnimationFrame(step);
|
||||
} else {
|
||||
activeScrollAnimation = 0;
|
||||
}
|
||||
};
|
||||
|
||||
activeScrollAnimation = requestAnimationFrame(step);
|
||||
};
|
||||
|
||||
document.querySelectorAll('a[href^="#"]').forEach(link => {
|
||||
link.addEventListener('click', e => {
|
||||
@@ -40,7 +76,7 @@ const {
|
||||
if (!target) return;
|
||||
e.preventDefault();
|
||||
const top = target.getBoundingClientRect().top + window.scrollY - getOffset();
|
||||
window.scrollTo({ top, behavior: 'smooth' });
|
||||
animateScrollTo(top);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user