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 [isDisabled, setIsDisabled] = useState(false); const [buttonText, setButtonText] = useState("Click me"); const disableButton = () => { setIsDisabled(true); setButtonText("Wait for 5 seconds..."); setTimeout(() => { setIsDisabled(false); setButtonText("Click me"); }, 5000); }; return ( <div className="container"> <h3>React Js Disable Button for 5 Seconds</h3> <button id="myButton" onClick={disableButton} disabled={isDisabled} className={isDisabled ? "disabled" : ""} > <span>{buttonText}</span> {isDisabled && <span class="spinner"></span>} </button> </div> ); } ReactDOM.render(<App />, document.getElementById("app")); </script> <style> body { font-family: Arial, sans-serif; background-color: #f7f7f7; } .container { max-width: 500px; margin: 50px auto; padding: 20px; border-radius: 8px; box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1); background-color: #ffffff; } h3 { margin-top: 0; text-align: center; color: #333333; } button { display: block; width: 100%; padding: 12px; font-size: 16px; border: none; border-radius: 4px; background-color: #3498db; color: #ffffff; cursor: pointer; position: relative; transition: background-color 0.3s ease-in-out; } button span { display: inline-block; margin-right: 10px; } .spinner { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); border: 4px solid rgba(255, 255, 255, 0.3); border-top: 4px solid #ffffff; border-radius: 50%; width: 20px; height: 20px; animation: spin 1s linear infinite; } @keyframes spin { 0% { transform: translate(-50%, -50%) rotate(0deg); } 100% { transform: translate(-50%, -50%) rotate(360deg); } } button:disabled { background-color: #bdc3c7; cursor: not-allowed; } </style> </body> </html>