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 } = React; function App() { const [imageURL, setImageURL] = useState(null); // Function to handle file input change const handleImageUpload = (event) => { const file = event.target.files[0]; if (file) { // Create a URL for the uploaded image const imageUrl = URL.createObjectURL(file); setImageURL(imageUrl); } }; return ( <div className='container'> <h3>React Js Get Image URL After Upload Image</h3> <input type="file" className="file-input" onChange={handleImageUpload} /> {imageURL && <img src={imageURL} alt="Uploaded" className="uploaded-image" />} {imageURL && <p className="image-url">Image URL: {imageURL}</p>} </div> ); } ReactDOM.render(<App />, document.getElementById('app')); </script> <style> /* Container styles */ .container { text-align: center; padding: 20px; border-radius: 10px; box-shadow: 0 0 10px rgba(0, 0, 0, 0.2); max-width: 400px; margin: 0 auto; } .file-input { display: inline-block; padding: 10px 20px; background-color: #3498db; color: #fff; border-radius: 5px; cursor: pointer; transition: background-color 0.3s ease; } .file-input+label:hover { background-color: #2980b9; } /* Uploaded image styles */ .uploaded-image { max-width: 100%; margin-top: 20px; border-radius: 5px; box-shadow: 0 0 5px rgba(0, 0, 0, 0.2); } /* Image URL text styles */ .image-url { font-size: 16px; color: #333; margin-top: 10px; } /* Optional: Add some animation to the uploaded image */ .uploaded-image { transition: transform 0.3s ease; } .uploaded-image:hover { transform: scale(1.1); } </style> </body> </html>