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 [isFlipped, setIsFlipped] = useState(false); const handleHover = () => { setIsFlipped(!isFlipped); }; return ( <div className='container'> <h3>React Js Image flip on hover</h3> <div className={`flip-image ${isFlipped ? 'flipped' : ''}`} onMouseEnter={handleHover} onMouseLeave={handleHover} > <div className="flip-image-inner"> <div className="front"> <img src='https://www.sarkarinaukriexams.com/images/editor/1695619083mountains-g2cad05fa6_640.jpg' alt="Front" /> </div> <div className="back"> <img src='https://www.sarkarinaukriexams.com/images/editor/1695618999tree-g8d108af7f_640.jpg' alt="Back" /> </div> </div> </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); } /* Flip Image Container */ .flip-image { width: 100%; height: 400px; perspective: 1000px; position: relative; } .flip-image-inner { width: 100%; height: 100%; transform-style: preserve-3d; transition: transform 0.5s; } .flip-image.flipped .flip-image-inner { transform: rotateY(180deg); } /* Front and Back */ .front, .back { width: 100%; height: 100%; position: absolute; backface-visibility: hidden; } .front { transform: rotateY(0deg); } .back { transform: rotateY(180deg); } /* Images */ img { width: 100%; height: 100%; cursor: pointer; } </style> </body> </html>