右擊新建,新建一個(gè)txt文件

粘貼復(fù)制以下代碼




<!doctype html><html><head><meta charset=&#34;utf-8&#34;><title>星空屏保</title><style>html,body { height" />

国产成人精品无码青草_亚洲国产美女精品久久久久∴_欧美人与鲁交大毛片免费_国产果冻豆传媒麻婆精东

15158846557 在線咨詢 在線咨詢
15158846557 在線咨詢
所在位置: 首頁 > 營銷資訊 > 網(wǎng)站運(yùn)營 > 編寫一個(gè)HTML文件實(shí)現(xiàn)炫酷動(dòng)態(tài)星空圖

編寫一個(gè)HTML文件實(shí)現(xiàn)炫酷動(dòng)態(tài)星空圖

時(shí)間:2023-06-07 12:27:02 | 來源:網(wǎng)站運(yùn)營

時(shí)間:2023-06-07 12:27:02 來源:網(wǎng)站運(yùn)營

編寫一個(gè)HTML文件實(shí)現(xiàn)炫酷動(dòng)態(tài)星空圖:首先,打開電腦

右擊新建,新建一個(gè)txt文件

粘貼復(fù)制以下代碼




<!doctype html><html><head><meta charset="utf-8"><title>星空屏保</title><style>html,body { height: 100%; max-width: 100%; margin: 0; overflow: hidden; font-family: sans-serif}#space { width: 100%}#warp { position: absolute; z-index: 9; bottom: 0; left: 0; right: 0; margin: 20px auto; color: rgba(209, 255, 255, 1); border: 2px solid; padding: 1em; width: 10em; text-align: center; font-weight: 700; font-size: 1.2em; display: inline-block; text-decoration: none; background: rgba(0, 0, 0, 0.8)}</style></head><body><canvas id="space"></canvas><a href="#" id="warp">WARP SPEED</a><script>//based on an Example by @curranwindow.requestAnimFrame = (function(){ return window.requestAnimationFrame})();var canvas = document.getElementById("space");var c = canvas.getContext("2d");var numStars = 1900;var radius = '0.'+Math.floor(Math.random() * 9) + 1 ;var focalLength = canvas.width *2;var warp = 0;var centerX, centerY;var stars = [], star;var i;var animate = true;initializeStars();function executeFrame(){ if(animate) requestAnimFrame(executeFrame); moveStars(); drawStars();}function initializeStars(){ centerX = canvas.width / 2; centerY = canvas.height / 2; stars = []; for(i = 0; i < numStars; i++){ star = { x: Math.random() * canvas.width, y: Math.random() * canvas.height, z: Math.random() * canvas.width, o: '0.'+Math.floor(Math.random() * 99) + 1 }; stars.push(star); }}function moveStars(){ for(i = 0; i < numStars; i++){ star = stars[i]; star.z--; if(star.z <= 0){ star.z = canvas.width; } }}function drawStars(){ var pixelX, pixelY, pixelRadius; // Resize to the screen if(canvas.width != window.innerWidth || canvas.width != window.innerWidth){ canvas.width = window.innerWidth; canvas.height = window.innerHeight; initializeStars(); } if(warp==0) {c.fillStyle = "rgba(0,10,20,1)"; c.fillRect(0,0, canvas.width, canvas.height);} c.fillStyle = "rgba(209, 255, 255, "+radius+")"; for(i = 0; i < numStars; i++){ star = stars[i]; pixelX = (star.x - centerX) * (focalLength / star.z); pixelX += centerX; pixelY = (star.y - centerY) * (focalLength / star.z); pixelY += centerY; pixelRadius = 1 * (focalLength / star.z); c.fillRect(pixelX, pixelY, pixelRadius, pixelRadius); c.fillStyle = "rgba(209, 255, 255, "+star.o+")"; //c.fill(); }}document.getElementById('warp').addEventListener("click",function(e){ window.c.beginPath(); window.c.clearRect(0, 0, window.canvas.width, window.canvas.height); window.warp = warp ? 0 : 1; executeFrame();});executeFrame();</script></body></html>


復(fù)制進(jìn)txt文件后,快捷鍵ctrl+s或點(diǎn)擊保存,右擊該txt文件,選擇重命名,將txt后綴改為html,

彈出確認(rèn)更改擴(kuò)展名,點(diǎn)擊確認(rèn)。

然后雙擊運(yùn)行html文件,即可出現(xiàn)畫面。




點(diǎn)擊WARP SPEED后,出現(xiàn)以下畫面



關(guān)鍵詞:動(dòng)態(tài),星空,實(shí)現(xiàn),文件,編寫

74
73
25
news

版權(quán)所有? 億企邦 1997-2025 保留一切法律許可權(quán)利。

為了最佳展示效果,本站不支持IE9及以下版本的瀏覽器,建議您使用谷歌Chrome瀏覽器。 點(diǎn)擊下載Chrome瀏覽器
關(guān)閉