martocode / assignment2-hacktiv8

0 stars 0 forks source link

scrollIntoView only works with smooth #1

Open martocode opened 3 years ago

martocode commented 3 years ago
scrollTo = () => {
        let currentWin = this.props.location.hash;
        const hasAnchor = currentWin.includes("#");
        if (hasAnchor) {
            const goTo = document.querySelector(currentWin);
            console.log(goTo, "www");
            if (goTo) {
                goTo.scrollIntoView({ behavior: "smooth" }); // Doesn't work with instant
            }
        }
        // this.awards.current.scrollIntoView({ behavior: "auto" });
    };
martocode commented 3 years ago

Fixed by adding setTimeout to 500 ms

if (goTo) {
    setTimeout(() => {
    goTo.scrollIntoView({ behavior: "instant" }); // Doesn't work with instant
    }, 500)
}