mauricevancooten / react-anchor-link-smooth-scroll

React component for anchor links using the smooth scroll polyfill.
243 stars 31 forks source link

Cannot Scroll From another component #13

Closed danielnuwin closed 6 years ago

danielnuwin commented 6 years ago

Can you use Anchor link where the id is on another component? I cannot scroll to the id when the Anchorlink is on another component. Does it have to be on the same component to work?

Navbar.js component
render() {
        return (
            <div>     
                 <AnchorLink href='#section1'>section1</AnchorLink>
                 <AnchorLink href='#section2'>section2</AnchorLink>
                 <AnchorLink href='#section3'>section3</AnchorLink>
                 <AnchorLink href='#section4'>section4</AnchorLink>
            </div>

        );
    }
Home.js component
 render() {
        return (
            <div>
                <Parallax strength={500}>
                    <ScrollAnimation delay={1000} animateIn="fadeIn" animateOnce={true}>
                        <CarouselIntro id="section1"/>
                    </ScrollAnimation>
                </Parallax>

                </Parallax>
                <Parallax strength={500}>
                    <BlogPage id="section2"/>
                </Parallax>

                <Parallax strength={500}>
                    <ScrollAnimation animateIn="fadeIn" animateOnce={true}>
                        <GalleryContainer id="section3"/>
                    </ScrollAnimation>
                </Parallax>

                <Parallax strength={500}>
                    <BlogPage id="section4" />
                </Parallax>

            </div>

        );
    }
danielnuwin commented 6 years ago

Found Solution, I have to wrap my components in a div and set ID there instead.