screen_rotation
Copied to Clipboard
<!DOCTYPE html> <html> <head> <meta charset="UTF-8" /> <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, useEffect } = React; function App() { const images = [ "https://www.sarkarinaukriexams.com/images/import/sne4446407201.png", "https://www.sarkarinaukriexams.com/images/import/sne86811832.png", "https://www.sarkarinaukriexams.com/images/import/sne10272423583.png", "https://www.sarkarinaukriexams.com/images/import/sne1586776004.png", "https://www.sarkarinaukriexams.com/images/import/sne20464172895.png", ]; const [currentImageIndex, setCurrentImageIndex] = useState(0); useEffect(() => { const interval = setInterval(() => { setCurrentImageIndex((prevIndex) => (prevIndex + 1) % images.length); }, 5000); return () => clearInterval(interval); }, []); return ( <div className='container'> <h3>React Js Change Image Every 5 Seconds</h3> <img className="image" src={images[currentImageIndex]} alt="Changing Image" /> </div> ); } ReactDOM.render(<App />, document.getElementById("app")); </script> <style> * { box-sizing: border-box; } .container { padding: 20px; border-radius: 8px; box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); text-align: center; max-width: 600px; margin: 0 auto; } .image { max-width: 100%; height: auto; } .image:hover { transform: scale(1.1); } </style> </body> </html>