HTMLify
Name.html
Views: 478 | Author: amar
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 | <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Smooth Sliding Typing</title> <style> body { font-family: Arial, sans-serif; margin: 0; padding: 0; background: #181818; color: #fff; display: flex; flex-direction: column; align-items: center; justify-content: center; height: 100vh; } input { width: 80%; padding: 10px; margin-bottom: 20px; font-size: 18px; } #screen { width: 80%; height: 300px; border: 2px solid #fff; position: relative; background: #222; overflow: hidden; cursor: crosshair; } .char { position: absolute; font-size: 20px; white-space: nowrap; transition: all 0.2s ease-in-out; /* Smooth transition for appearance */ } </style> </head> <body> <input type="text" id="userInput" placeholder="Enter your text here" /> <div id="screen"></div> <script> const inputField = document.getElementById('userInput'); const screen = document.getElementById('screen'); let text = ''; let currentIndex = 0; let lastPosition = { x: 0, y: 0 }; // Keep track of last printed position inputField.addEventListener('input', (e) => { text = e.target.value; // Update text from input currentIndex = 0; // Reset typing index screen.innerHTML = ''; // Clear the screen }); screen.addEventListener('mousemove', (e) => { const distance = Math.sqrt( Math.pow(e.offsetX - lastPosition.x, 2) + Math.pow(e.offsetY - lastPosition.y, 2) ); // Only add a character if the mouse moves a certain distance (for smoothness) if (distance > 15 && currentIndex < text.length) { const char = document.createElement('span'); char.textContent = text[currentIndex]; char.className = 'char'; // Position the character based on mouse location char.style.left = `${e.offsetX}px`; char.style.top = `${e.offsetY}px`; screen.appendChild(char); // Add character to the screen currentIndex++; // Update last position lastPosition = { x: e.offsetX, y: e.offsetY }; } }); </script> </body> </html> |