<!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>

WebDevelovermentReliesonHtml,CSS和JavaScript:1)HTMLStructuresContent,2)CSSStyleSIT和3)JavaScriptAddSstractivity,形成thebasisofmodernWebemodernWebExexperiences。

HTML的作用是通過標籤和屬性定義網頁的結構和內容。 1.HTML通過到、等標籤組織內容,使其易於閱讀和理解。 2.使用語義化標籤如、等增強可訪問性和SEO。 3.優化HTML代碼可以提高網頁加載速度和用戶體驗。

htmlisaspecifictypefodyfocusedonstructuringwebcontent,而“代碼” badlyLyCludEslanguagesLikeLikejavascriptandPytyPythonForFunctionality.1)htmldefineswebpagertuctureduseTags.2)“代碼”代碼“ code” code code code codeSpassSesseseseseseseseAwiderRangeLangeLangeforLageforLogageforLogicIctInterract

HTML、CSS和JavaScript是Web開發的三大支柱。 1.HTML定義網頁結構,使用標籤如、等。 2.CSS控製網頁樣式,使用選擇器和屬性如color、font-size等。 3.JavaScript實現動態效果和交互,通過事件監聽和DOM操作。

HTML定義網頁結構,CSS負責樣式和佈局,JavaScript賦予動態交互。三者在網頁開發中各司其職,共同構建豐富多彩的網站。

HTML適合初學者學習,因為它簡單易學且能快速看到成果。 1)HTML的學習曲線平緩,易於上手。 2)只需掌握基本標籤即可開始創建網頁。 3)靈活性高,可與CSS和JavaScript結合使用。 4)豐富的學習資源和現代工具支持學習過程。

AnexampleOfAstartingTaginHtmlis,beginSaparagraph.startingTagSareEssentialInhtmlastheyInitiateEllements,defiteTheeTheErtypes,andarecrucialforsstructuringwebpages wepages webpages andConstructingthedom。

如何設計菜單中的虛線分割效果?在設計菜單時,菜名和價格的左右對齊通常不難實現,但中間的虛線或點如何...


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

AI Hentai Generator
免費產生 AI 無盡。

熱門文章

熱工具

Atom編輯器mac版下載
最受歡迎的的開源編輯器

MantisBT
Mantis是一個易於部署的基於Web的缺陷追蹤工具,用於幫助產品缺陷追蹤。它需要PHP、MySQL和一個Web伺服器。請查看我們的演示和託管服務。

ZendStudio 13.5.1 Mac
強大的PHP整合開發環境

EditPlus 中文破解版
體積小,語法高亮,不支援程式碼提示功能

SecLists
SecLists是最終安全測試人員的伙伴。它是一個包含各種類型清單的集合,這些清單在安全評估過程中經常使用,而且都在一個地方。 SecLists透過方便地提供安全測試人員可能需要的所有列表,幫助提高安全測試的效率和生產力。清單類型包括使用者名稱、密碼、URL、模糊測試有效載荷、敏感資料模式、Web shell等等。測試人員只需將此儲存庫拉到新的測試機上,他就可以存取所需的每種類型的清單。