<script src="https://unpkg.com/react@17.0.2/umd/react.development.js"></script>
<script src="https://unpkg.com/react-dom@17.0.2/umd/react-dom.development.js"></script>
<script src="https://unpkg.com/@babel/standalone@7.14.7/babel.min.js"></script>
<script type="text/babel">
const { useState, useEffect, useRef } = React;
const myElementRef = useRef(null);
const [positionTop, setPositionTop] = useState(0);
const [positionLeft, setPositionLeft] = useState(0);
const handleScroll = () => {
const el = myElementRef.current;
setPositionTop(el.scrollTop);
setPositionLeft(el.scrollLeft);
const element = myElementRef.current;
element.addEventListener("scroll", handleScroll);
element.removeEventListener("scroll", handleScroll);
<div className="container">
<h3>React Get Element Scroll Position</h3>
Font Awesome is a popular icon set used by designers and
developers worldwide. It was created by Dave Gandy in 2012 and
has since become one of the most widely used icon sets on the
Font Awesome icons are vector-based, which means they can be
scaled to any size without losing their quality or becoming
The Font Awesome icon set includes over 7,000 icons, including
popular icons such as social media icons, navigation icons, and
The icons are divided into categories such as web application
icons, accessibility icons, and transportation icons, making it
easy for designers to find the right icon for their needs.
One of the biggest benefits of using Font Awesome icons is the
ease of implementation. <br />
The icons can be easily added to a website or application using
either CSS classes or JavaScript. This means that even designers
and developers who are not familiar with vector graphics can
easily use Font Awesome icons on their projects.
Font Awesome is a popular icon set used by designers and
developers worldwide. It was created by Dave Gandy in 2012 and
has since become one of the most widely used icon sets on the
Font Awesome icons are vector-based, which means they can be
scaled to any size without losing their quality or becoming
The Font Awesome icon set includes over 7,000 icons, including
popular icons such as social media icons, navigation icons, and
The icons are divided into categories such as web application
icons, accessibility icons, and transportation icons, making it
easy for designers to find the right icon for their needs.
One of the biggest benefits of using Font Awesome icons is the
ease of implementation. <br />
The icons can be easily added to a website or application using
either CSS classes or JavaScript. This means that even designers
and developers who are not familiar with vector graphics can
easily use Font Awesome icons on their projects.
<p>Scroll Top: {positionTop} px</p>
<p>Scroll left: {positionLeft} px</p>
ReactDOM.render(<App />, document.getElementById("app"));
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
overflow: auto; /* or overflow-x: scroll; */
white-space: nowrap; /* Ensures the content stays in a single line */