This commit is contained in:
zhangjianjun 2026-04-15 13:14:14 +08:00
parent cc85c497c9
commit fc372a0278
3 changed files with 8 additions and 8 deletions

View File

@ -40,7 +40,7 @@ export default function SwiperCardSection({ data, disableHover=false }: { data:
}
}, [hashId, data.cardItems, swiperRef])
return (
<section className={styles.swiperCardSection} id={location.key + hashId} style={{ backgroundImage: `url(${data.backgroundImage})` }}>
<section className={styles.swiperCardSection} id={location.pathname + hashId} style={{ backgroundImage: `url(${data.backgroundImage})` }}>
<SectionTitle title={data.title} />
<div className={styles.carouselWrapper} >
{activeIndex > 0 && (

View File

@ -48,7 +48,7 @@ export default function TopTabsSection({ data, className }: { data: Data, classN
const sideSlides = sideImageToSlides(data.tabItems[activeIndex]?.sideImage);
return (
<section id={location.key + hashId} className={`${styles.topTabsSection} ${className}`} style={{ backgroundImage: `url(${data.backgroundImage})` }}>
<section id={location.pathname + hashId} className={`${styles.topTabsSection} ${className}`} style={{ backgroundImage: `url(${data.backgroundImage})` }}>
<div aria-hidden="true">
{data.tabItems.map((item,index) => (
<div key={item.tabName} style={{ height: 0, overflow: "hidden" }} />

View File

@ -9,7 +9,7 @@ const useHashScroll = () => {
useEffect(() => {
if (!location.hash) {
if(navType === 'PUSH') {
scrollToWithLenis(0, { immediate: false });
// scrollToWithLenis(0, { immediate: false });
}
return;
}
@ -19,15 +19,13 @@ const useHashScroll = () => {
const maxAttempts = 120;
const targetId = decodeURIComponent(location.hash.slice(1));
const tryScrollToHash = () => {
const element = targetId ? document.getElementById(location.key + targetId) : null;
console.log('location.key + id', location.key + targetId)
console.log('element', element)
const element = targetId ? document.getElementById(location.pathname + targetId) : null;
if (element) {
const header = document.querySelector("header");
const headerHeight = header?.getBoundingClientRect().height ?? 7.5 * 16;
scrollToWithLenis(element, {
offset: -headerHeight,
duration: 1.1,
duration: 1.5,
});
return;
}
@ -38,9 +36,11 @@ const useHashScroll = () => {
}
};
// rafId = window.requestAnimationFrame(tryScrollToHash);
setTimeout(() => {
rafId = window.requestAnimationFrame(tryScrollToHash);
},50)
},100)
return () => window.cancelAnimationFrame(rafId);
}, [location.pathname, location.hash, navType]);
};