随机运动小球 - html
目的是为了训练眼球运动
直接将如下代码到保存为html文件打开即可
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 | <! DOCTYPE html> < html > < head > < meta charset="UTF-8"> < meta name="viewport" content="width=device-width, initial-scale=1.0"> < title >随机运动小球</ title > < style > body { background-color: black; margin: 0; height: 100vh; width: 100vw; overflow: hidden; } </ style > </ head > < body > < svg id="mySVG" height="200" width="200"> < circle id="myCircle1" cx="50" cy="50" r="40" fill="#27202075" /> < circle id="myCircle" cx="50" cy="50" r="40" fill="#27202075" /> < text id="myCircle1Text" x="50" y="55" font-size="20px" text-anchor="middle" fill="pink">·</ text > < text id="myCircleText" x="50" y="55" font-size="20px" text-anchor="middle" fill="pink">·</ text > </ svg > < script > var svg = document.getElementById('mySVG'); var circle = document.getElementById('myCircle'); var circle1 = document.getElementById('myCircle1'); var text = document.getElementById('myCircleText'); var text1 = document.getElementById('myCircle1Text'); // Function to get random number up to max var random = function(max) { return Math.floor(Math.random() * max); } // Set svg and circle size svg.setAttribute('width', window.innerWidth - 50); svg.setAttribute('height', window.innerHeight - 50); // Animate the circle to a new position, and repeat var animate = function() { let width = random(window.innerWidth - 100) let height = random(window.innerHeight - 100) circle.setAttribute('cx', width); circle.setAttribute('cy', height); let time = random(5) + 1 // Apply a random duration for the next animation circle.style.transitionDuration = (time) + 's'; setTimeout(animate, (time) * 1000); text.setAttribute('x', width); text.setAttribute('y', height + 5); text.style.transitionDuration = (time) + 's'; } // Animate the circle to a new position, and repeat var animate1 = function() { let width = random(window.innerWidth - 100) let height = random(window.innerHeight - 100) circle1.setAttribute('cx', width); circle1.setAttribute('cy', height); // Apply a random duration for the next animation let time1 = random(5) + 1 circle1.style.transitionDuration = (time1) + 's'; text1.setAttribute('x', width); text1.setAttribute('y', height + 5); text1.style.transitionDuration = (time1) + 's'; setTimeout(animate1, (time1) * 1000); } // Start the animation animate(); animate1(); </ script > </ body > </ html > |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具