React - Scroll events

0 votes
132 views
added May 14, 2019 in React by LC Marshal Captain (25,770 points)
// declare variable
const scrollToLocationRefMobile = () => window.scrollTo(0, locationRef.current.offsetTop + 200);

 

<!--Usage-->
<a className="view-map" onClick={scrollToLocationRefMobile}>
    <i className="location-icon"></i>
    View on the map
</a>

 

1 Response

0 votes
responded May 14, 2019 by LC Marshal Captain (25,770 points)
// variable
const scrollToLocationRef = () => {
    window.scrollTo(0, locationRef.current.offsetTop + 460);
};
<!--usage-->
{isValidCoordinates(assetLocation) && (
    <li className="nav-item" onClick={scrollToLocationRef}>
        <a className="nav-link">Location</a>
    </li>
)}

 

lazacode.org - Malaysia's programming knowledge sharing platform, where everyone can share their finding as reference to others.
...