screen_rotation
Copied to Clipboard
<!DOCTYPE html> <html> <head> <meta charset="UTF-8" /> <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> </head> <body> <div id="app"></div> <script type="text/babel"> const { useState, useEffect, useRef } = React; function App() { const myElementRef = useRef(null); const [positionTop, setPositionTop] = useState(0); const [positionLeft, setPositionLeft] = useState(0); useEffect(() => { const handleScroll = () => { const el = myElementRef.current; setPositionTop(el.scrollTop); setPositionLeft(el.scrollLeft); }; const element = myElementRef.current; element.addEventListener("scroll", handleScroll); return () => { element.removeEventListener("scroll", handleScroll); }; }, []); return ( <div className="container"> <h3>React Get Element Scroll Position</h3> <div ref={myElementRef}> <p> 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 web. <br /> Font Awesome icons are vector-based, which means they can be scaled to any size without losing their quality or becoming pixelated. </p> <p> The Font Awesome icon set includes over 7,000 icons, including popular icons such as social media icons, navigation icons, and interface icons. <br /> 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. </p> <p> 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> <p> 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 web. <br /> Font Awesome icons are vector-based, which means they can be scaled to any size without losing their quality or becoming pixelated. </p> <p> The Font Awesome icon set includes over 7,000 icons, including popular icons such as social media icons, navigation icons, and interface icons. <br /> 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. </p> <p> 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> </div> <p>Scroll Top: {positionTop} px</p> <p>Scroll left: {positionLeft} px</p> </div> ); } ReactDOM.render(<App />, document.getElementById("app")); </script> <style> .container { max-width: 500px; margin: 0 auto; padding: 20px; border-radius: 8px; box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1); } .container h3 { font-size: 24px; margin-bottom: 20px; } .container p { font-size: 14px; line-height: 1.5; margin-bottom: 10px; } .container div { max-width: 100%; height: 200px; overflow: auto; /* or overflow-x: scroll; */ white-space: nowrap; /* Ensures the content stays in a single line */ } </style> </body> </html>