screen_rotation
Copied to Clipboard
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <script src="https://cdnjs.cloudflare.com/ajax/libs/react/17.0.2/umd/react.development.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/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; function App() { const [isHovered, setIsHovered] = useState(false); return ( <div className='container'> <h1>React Js Image Zoom on Hover</h1> <div className={`image-container ${isHovered ? 'zoomed' : ''}`} onMouseEnter={() => setIsHovered(true)} onMouseLeave={() => setIsHovered(false)} > <img src="https://www.sarkarinaukriexams.com/images/editor/1695619083mountains-g2cad05fa6_640.jpg" // Replace with your image URL alt="Zoomable Image" className="zoom-image" /> </div> </div> ); } ReactDOM.render(<App />, document.getElementById("app")); </script> <style> * { box-sizing: border-box; } .container { margin: 0 auto; width: 600px; text-align: center; background: #fff; border-radius: 5px; padding: 20px; box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2); } .image-container { display: inline-block; overflow: hidden; transition: transform 0.3s; } .zoom-image { width: 300px; /* Adjust the width as needed */ height: 300px; /* Adjust the height as needed */ object-fit: cover; } .zoomed { transform: scale(1.2); /* Adjust the scale factor for zoom effect */ } </style> </body> </html>