目标是将一个部分显示在视图中,然后暂停并滚动该部分中存在的水平滚动条的全长,然后继续到下一个部分。我已经能够实现滚动水平滚动条,但它是链接到整个页面的Y滚动,而不是生效&完成时,只有容器是在视图中。
以下是我的代码:
export default function TechStack({ darkMode }: TechStackProps) {
const targetRef = useRef(null);
const { scrollYProgress } = useScroll();
const translateElement = useTransform(
scrollYProgress,
[0.1, 0.8],
["0%", "-57%"]
);
const opacitySection = useTransform(
scrollYProgress,
[0.1, 0.7, 0.9],
[0, 0, 1]
);
return (
<section ref={targetRef}>
<div
style={{
// opacity: opacitySection,
zIndex: 20,
}}
className={`relative ${
darkMode ? "dark" : `light`
} flex flex-col items-center justify-center lg:items-start pt-[30%] md:pt-40 pb-20 md:w-full lg:h-screen lg:pb-40 `}
>
<div className="max-w-5xl p-4 z-20 lg:pl-[4rem] sticky top-20">
<h1 className="font-black text-6xl px-4 py-4">
DESIGN.
<br />
DEVELOP.
<br />
TEST.
</h1>
<p className="font-light text-2xl leading-1 p-4">
Building a good digital experience requires an even better tool-set
of technologies. These are some of the technologies I have worked
with recently.
</p>
</div>
<motion.div style={{ x: translateElement }} className="translate-this-div-on-scroll">
<div className="tech-stack w-full flex flex-nowrap px-[2rem] md:px-[5rem] gap-8 py-8 z-20 overflow-hidden">
<TechContainer
darkMode={darkMode}
technologyCategory="FRONT-END DEVELOPMENT"
technologyData={frontEndTechnologies}
/>
<TechContainer
darkMode={darkMode}
technologyCategory="BACK-END DEVELOPMENT"
technologyData={backEndTechnologies}
/>
<TechContainer
darkMode={darkMode}
technologyCategory="DATABASE MANAGEMENT"
technologyData={databaseTechnologies}
/>
<TechContainer
darkMode={darkMode}
technologyCategory="SERVERS"
technologyData={serverTechnologies}
/>
<TechContainer
darkMode={darkMode}
technologyCategory="VERSION CONTROL"
technologyData={versionControlTechnologies}
/>
<TechContainer
darkMode={darkMode}
technologyCategory="DESIGN"
technologyData={designTechnologies}
/>
<TechContainer
darkMode={darkMode}
technologyCategory="IDE"
technologyData={IDE}
/>
<TechContainer
darkMode={darkMode}
technologyCategory="OTHER TECHNOLOGIES"
technologyData={otherTechnologies}
/>
</div>
</motion.div>
</div>
</section>
);
}
字符串
1条答案
按热度按时间toiithl61#
这是我的解决方案,希望对你有所帮助。
字符串