繁体   English   中英

如何滚动到 React 中的组件?

[英]How do I scroll to a component in React?

我想知道如何滚动到组件而不是即时查看组件

所以我的概述组件中有以下内容

<a className="more-text group" href="#about">
     <h3 className="title">+ </h3>
     <h3 className="title">learn more</h3>
</a>

并且组件保留在我的 Home 组件中

class Home extends React.Component {
    render() {
        return (
            <div>
                {/* Header */}
                <Header />

                {/*Overview Component*/}
                <Overview />

                {/* About Component*/}
                <About />

                {/*Footer Component*/}
                <Footer />
            </div>
        );
    }
}

I see you want to achieve this with url hash parameters, So go ahead and simply assign ids to your components, and change the url when you want to scroll.

<Header />

{/*Overview Component*/}
<Overview id="overview" />

{/* About Component*/}
<About id="about" />

{/*Footer Component*/}
<Footer id="footer" />

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM