canvas-a11htmlANDcanvas.html_html/css_WEB-ITnose
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title>Document</title></head><style> #canvas-wrapper{ width: 1200px; height: 800px; position: relative; margin:50px auto; } #canvas{ border: 1px #ddd solid; } #controller{ position: absolute; top:30px; left:30px; background:rgba(0,85,116,0.7); padding:5px 20px 25px 20px; border-radius: 10px 10px; } #controller h1{ color: white; font-weight: bold; font-family: "Microsoft Yahei"; } #controller #canvas-btn{ display: inline-block; background: #8b0; color: white; font-size: 14px; padding: 5px 15px; } #controller #canvas-btn:hover{ text-decoration: none; background:#7a0; } #controller .color-btn{ display: inline-block; padding:5px 15px; border-radius: 6px 6px; font-size: 14px; margin-top: 10px; margin-right: 5px; text-decoration: none; } #controller .color-btn:hover{ text-decoration: none; } #controller #white-color-btn{ background-color: white; } #controller #black-color-btn{ background-color: black; }</style><body> <div id="canvas-wrapper"> <canvas id="canvas"> 当前游览器不支持Canvas,请更换游览器再试! </canvas> <div id="controller"> <h1 id="Canvas-绘图之旅">Canvas 绘图之旅</h1> <a href="#" id="canvas-btn">stop</a> <a href="#" class="color-btn" id="white-color-btn">white</a> <a href="#" class="color-btn" id="black-color-btn">black</a> </div> </div> <script> var balls = []; var isMoving = true; var themeColor = "white"; var canvas = document.getElementById("canvas"); window.onload = function(){ canvas.width = 1200; canvas.height = 800; if(canvas.getContext('2d')){ var context = canvas.getContext('2d'); // 产生100个小球 for(var i=0;i<100;i++){ var R = Math.floor(Math.random()*255); var G = Math.floor(Math.random()*255); var B = Math.floor(Math.random()*255); var radius = Math.random()*50+20; aBall = { color : "rgb(" + R + "," + G + "," + B + ")", radius : radius, x : Math.random()*(canvas.width-2*radius) + radius, y : Math.random()*(canvas.height-2*radius) + radius, vx : (Math.random()*5 + 5) * Math.pow(-1,Math.floor(Math.random()*100)), vy : (Math.random()*5 + 5) * Math.pow(-1,Math.floor(Math.random()*100)), } balls[i] = aBall; } // 绘制并运动 setInterval(function(){ draw(context); if(isMoving){ update(canvas.width,canvas.height) } },50) // stop document.getElementById("canvas-btn").onclick = function(event){ if(isMoving){ isMoving = false; this.text = "start"; }else{ isMoving = true; this.text = "stop"; } return false; } // white document.getElementById("white-color-btn").onclick = function(event){ themeColor = "white"; return false; } // black document.getElementById("black-color-btn").onclick = function(event){ themeColor = "black"; return false; } }else{ alert("当前游览器不支持Canvas,请更换游览器再试!") } } function draw(cxt){ // var canvas = cxt.canvas; cxt.clearRect(0,0,canvas.width,canvas.height); if(themeColor == "black"){ console.log("black theme"); cxt.fillStyle = "black"; cxt.fillRect(0,0,canvas.width,canvas.height) } for(var i=0;i<balls.length;i++){ cxt.fillStyle = balls[i].color; cxt.beginPath(); cxt.arc(balls[i].x,balls[i].y,balls[i].radius,0,Math.PI*2); cxt.closePath(); cxt.fill(); } } function update(){ for(var i=0;i<balls.length;i++){ balls[i].x += balls[i].vx; balls[i].y += balls[i].vy; // 边缘检测 if(balls[i].x - balls[i].radius <= 0){ balls[i].vx = -balls[i].vx; balls[i].x = balls[i].radius; } if(balls[i].x + balls[i].radius >= canvas.width){ balls[i].vx = -balls[i].vx; balls[i].x = canvas.width - balls[i].radius; } if(balls[i].y - balls[i].radius <= 0){ balls[i].vy = -balls[i].vy; balls[i].y = balls[i].radius; } if(balls[i].y + balls[i].radius >= canvas.height){ balls[i].vy = -balls[i].vy; balls[i].y = canvas.height - balls[i].radius; } } } </script></body></html>

热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

AI Hentai Generator
免费生成ai无尽的。

热门文章

热工具

记事本++7.3.1
好用且免费的代码编辑器

SublimeText3汉化版
中文版,非常好用

禅工作室 13.0.1
功能强大的PHP集成开发环境

Dreamweaver CS6
视觉化网页开发工具

SublimeText3 Mac版
神级代码编辑软件(SublimeText3)

公众号网页更新缓存,这玩意儿,说简单也简单,说复杂也够你喝一壶的。你辛辛苦苦更新了公众号文章,结果用户打开还是老版本,这滋味,谁受得了?这篇文章,咱就来扒一扒这背后的弯弯绕绕,以及如何优雅地解决这个问题。读完之后,你就能轻松应对各种缓存难题,让你的用户始终体验到最新鲜的内容。先说点基础的。网页缓存,说白了就是浏览器或者服务器为了提高访问速度,把一些静态资源(比如图片、CSS、JS)或者页面内容存储起来。下次访问时,直接从缓存里取,不用再重新下载,速度自然快。但这玩意儿,也是个双刃剑。新版本上线,

本文讨论了使用HTML5表单验证属性,例如必需的,图案,最小,最大和长度限制,以直接在浏览器中验证用户输入。

本文展示了使用CSS为网页中添加有效的PNG边框。 它认为,与JavaScript或库相比,CSS提供了出色的性能,详细介绍了如何调整边界宽度,样式和颜色以获得微妙或突出的效果

本文讨论了html&lt; datalist&gt;元素,通过提供自动完整建议,改善用户体验并减少错误来增强表格。Character计数:159

本文讨论了HTML&lt; Progress&gt;元素,其目的,样式和与&lt; meter&gt;元素。主要重点是使用&lt; progress&gt;为了完成任务和LT;仪表&gt;对于stati

本文解释了HTML5&lt; time&gt;语义日期/时间表示的元素。 它强调了DateTime属性对机器可读性(ISO 8601格式)的重要性,并在人类可读文本旁边,增强Accessibilit

本文讨论了HTML&lt; meter&gt;元素,用于在一个范围内显示标量或分数值及其在Web开发中的常见应用。它区分了&lt; meter&gt;从&lt; progress&gt;和前
