gemini-2.5-flash· Google LMArena Human Preference 140K
create a mouse cursor trail in javascript for me to paste in my browser console
- User
create a mouse cursor trail in javascript for me to paste in my browser console
- Assistant
Okay, this is a fun one! Here's a JavaScript snippet you can paste directly into your browser's console (F12 or Ctrl+Shift+I).
This code will:
- Create small, semi-transparent dots at your mouse cursor's position.
- Make these dots fade out and disappear after a short time.
- Randomize the size and color slightly for a more dynamic effect.
- Provide a function to easily stop the trail.
Instructions:
- Open your browser's developer console (usually by pressing
F12orCtrl+Shift+I). - Go to the "Console" tab.
- Copy the entire code block below.
- Paste it into the console and press
Enter. - Move your mouse around to see the trail!
(function() { // --- Configuration --- const TRAIL_OPTIONS = { dotMinSize: 5, // Minimum size of a dot in pixels dotMaxSize: 15, // Maximum size of a dot in pixels fadeDuration: 1000, // How long dots last in milliseconds creationInterval: 20, // Minimum time between dot creations in milliseconds maxDots: 300 // Maximum number of dots to keep in the DOM }; let lastCreationTime = 0; let trailDots = []; let trailHandler = null; // To store the mousemove handler for removal // --- Helper function to create a random color --- function getRandomColor() { const hue = Math.floor(Math.random() * 360); // 0-360 for full spectrum const saturation = Math.floor(Math.random() * 30) + 70; // 70-100% saturation const lightness = Math.floor(Math.random() * 20) + 60; // 60-80% lightness return `hsla(${hue}, ${saturation}%, ${lightness}%, 0.7)`; // 0.7 opacity } // --- Function to create and manage a single dot --- function createTrailDot(e) { const currentTime = Date.now(); if (currentTime - lastCreationTime < TRAIL_OPTIONS.creationInterval) { return; // Too soon since the last dot } lastCreationTime = currentTime; const dot = document.createElement('div'); const dotSize = Math.floor(Math.random() * (TRAIL_OPTIONS.dotMaxSize - TRAIL_OPTIONS.dotMinSize + 1)) + TRAIL_OPTIONS.dotMinSize; // Apply initial styles Object.assign(dot.style, { position: 'absolute', left: `${e.clientX - dotSize / 2}px`, // Center the dot on the cursor top: `${e.clientY - dotSize / 2}px`, // Center the dot on the cursor width: `${dotSize}px`, height: `${dotSize}px`, backgroundColor: getRandomColor(), borderRadius: '50%', pointerEvents: 'none', // Crucial: allows clicks/interactions with elements beneath opacity: '1', zIndex: '99999', // Ensure it's on top of most page content transition: `opacity ${TRAIL_OPTIONS.fadeDuration}ms ease-out, transform ${TRAIL_OPTIONS.fadeDuration}ms ease-out` }); // Add to body document.body.appendChild(dot); trailDots.push(dot); // Trigger fade after a tiny delay to ensure transition works // (Initial opacity needs to be rendered before it can transition to 0) setTimeout(() => { dot.style.opacity = '0'; dot.style.transform = 'scale(0.5)'; // Shrink slightly as it fades }, 10); // Remove from DOM after fade duration setTimeout(() => { if (dot.parentNode) { // Check if it's still in the DOM dot.remove(); // Remove from our tracking array const index = trailDots.indexOf(dot); if (index > -1) { trailDots.splice(index, 1); } } }, TRAIL_OPTIONS.fadeDuration + 50); // Give a little extra time for transition completion // Clean up old dots if we exceed the max while (trailDots.length > TRAIL_OPTIONS.maxDots) { const oldestDot = trailDots.shift(); // Get and remove the oldest dot if (oldestDot.parentNode) { oldestDot.remove(); } } } // --- Start the trail --- function startTrail() { if (trailHandler) { console.warn('Cursor trail is already running.'); return; } trailHandler = createTrailDot; document.addEventListener('mousemove', trailHandler); console.log('Cursor trail started! ✨'); console.log('To stop it, type: _stopCursorTrail() in the console.'); } // --- Stop and clean up the trail --- function stopTrail() { if (!trailHandler) { console.warn('Cursor trail is not running.'); return; } document.removeEventListener('mousemove', trailHandler); trailHandler = null; // Remove all existing dots trailDots.forEach(dot => { if (dot.parentNode) { dot.remove(); } }); trailDots = []; console.log('Cursor trail stopped and cleaned up. 👋'); } // --- Expose the stop function globally for easy access --- window._stopCursorTrail = stopTrail; // --- Start it automatically when the script runs --- startTrail(); })();
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.