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 } = React; function App() { const [imgSrc, setImgSrc] = useState( "https://www.sarkarinaukriexams.com/images/post/1683464736React_Js_Change_Image_Source_Url.jpg" ); const [updateSrc, setUpdateSrc] = useState("https://www.sarkarinaukriexams.com/images/bio/1696486335-bio.png"); // State for the dynamic image source const changeImg = () => { setImgSrc(updateSrc); }; return ( <div className='container'> <h3>React Js Change Image Src | Url Dynamically</h3> <input type="text" placeholder="Enter Image URL" value={updateSrc} onChange={(e) => setUpdateSrc(e.target.value)} /> <button onClick={changeImg}>Change Image</button> <img src={imgSrc} alt="Dynamic Image" /> </div> ); } ReactDOM.render(<App />, document.getElementById("app")); </script> <style> .container { max-width: 600px; margin: auto; text-align: center; padding: 20px; box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1); border-radius: 8px; } h3 { color: #333; } input { padding: 10px; margin: 10px 0; width: 100%; box-sizing: border-box; border: 1px solid #ccc; border-radius: 4px; } button { background-color: #4caf50; color: white; padding: 10px 20px; border: none; border-radius: 4px; cursor: pointer; } button:hover { background-color: #45a049; } img { max-width: 100%; height: auto; margin-top: 10px; border-radius: 4px; box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1); } </style> </body> </html>