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://cdnjs.cloudflare.com/ajax/libs/babel-standalone/6.26.0/babel.min.js"></script> </head> <body> <div id="app"></div> <script type="text/babel"> const { useState } = React; const ImageSwitcher = () => { const [isHovered, setIsHovered] = useState(false); const image1 = 'https://www.sarkarinaukriexams.com/images/editor/1691754246bird-g8b2ad9bcc_640.jpg'; const image2 = 'https://www.sarkarinaukriexams.com/images/editor/1691754318flower-gf39467e8f_640.jpg' const handleHover = () => { setIsHovered(!isHovered); }; return ( <div className="image-container"> <img src={isHovered ? image2 : image1} alt="Image" onMouseEnter={handleHover} onMouseLeave={handleHover} /> </div> ); }; const App = () => { return ( <div className="container"> <h2>React Js Change Image on Hover | Switcher</h2> <ImageSwitcher /> </div> ); }; ReactDOM.render(<App />, document.getElementById('app')); </script> <style> /* General styles */ * { box-sizing: border-box; font-family: Arial, sans-serif; } .container { display: flex; flex-direction: column; align-items: center; margin-top: 30px; } .image-container { position: relative; width: 200px; height: 200px; } .image-container img { width: 100%; height: 100%; object-fit: cover; transition: transform 0.3s ease-in-out; } .image-container img:hover { transform: scale(1.1); } </style> </body> </html>