HTML5是一種用于創建網頁和網頁應用程序的語言。隨著技術的不斷發展,HTML5已經成為了最流行的網頁開發語言之一。今天,我想分享一個關于HTML5星空表白頁面代碼的例子。代碼如下:
<!DOCTYPE html> <html> <head> <title>星空表白</title> <style> html, body { height: 100%; } body { background: linear-gradient(to bottom, #051937, #004d7a); background-attachment: fixed; background-size: cover; } canvas { position: absolute; top: 0; left: 0; width: 100%; height: 100%; z-index: -1; } h1 { font-family: sans-serif; font-size: 4rem; color: #fff; text-align: center; margin-top: 10%; } </style> </head> <body> <canvas id="canvas"></canvas> <h1>你是我的星空</h1> <script> // 創建畫布 var canvas = document.getElementById('canvas'); var ctx = canvas.getContext('2d'); // 設置畫布寬度和高度 canvas.width = window.innerWidth; canvas.height = window.innerHeight; // 創建一個星空的背景 var stars = []; var starCount = 1000; for (var i = 0; i< starCount; i++) { var x = Math.random() * canvas.width; var y = Math.random() * canvas.height; var size = Math.random() * 2; var brightness = Math.random() * 255; stars.push({x: x, y: y, size: size, brightness: brightness}); } // 繪制星空 ctx.fillStyle = '#fff'; for (var i = 0; i< stars.length; i++) { ctx.fillStyle = 'rgba(' + stars[i].brightness + ', ' + stars[i].brightness + ', ' + stars[i].brightness + ', 1)'; ctx.beginPath(); ctx.arc(stars[i].x, stars[i].y, stars[i].size, 0, 2 * Math.PI); ctx.fill(); } </script> </body> </html>文章完畢。以上代碼可以創建一個帶星空背景的浪漫表白頁面,向你的愛人表達你的愛意。
上一篇html5星期日設置