|
| 1 | + |
| 2 | +<!DOCTYPE html> |
| 3 | +<html lang="zh-CN"> |
| 4 | +<head> |
| 5 | + <meta charset="UTF-8"> |
| 6 | + <meta name="viewport" content="width=device-width, initial-scale=1.0"> |
| 7 | + <title>CST代码</title> |
| 8 | + <style> |
| 9 | + * { |
| 10 | + margin: 0; |
| 11 | + padding: 0; |
| 12 | + box-sizing: border-box; |
| 13 | + } |
| 14 | + body { |
| 15 | + font-family: 'Courier New', monospace; |
| 16 | + background-color: #000; |
| 17 | + color: #0f0; |
| 18 | + overflow: hidden; |
| 19 | + height: 100vh; |
| 20 | + display: flex; |
| 21 | + flex-direction: column; |
| 22 | + } |
| 23 | + #matrix { |
| 24 | + position: fixed; |
| 25 | + top: 0; |
| 26 | + left: 0; |
| 27 | + z-index: 0; |
| 28 | + opacity: 0.15; |
| 29 | + } |
| 30 | + header { |
| 31 | + position: relative; |
| 32 | + z-index: 2; |
| 33 | + padding: 20px; |
| 34 | + text-align: center; |
| 35 | + border-bottom: 1px solid #0f0; |
| 36 | + } |
| 37 | + .content { |
| 38 | + position: relative; |
| 39 | + z-index: 2; |
| 40 | + flex: 1; |
| 41 | + display: flex; |
| 42 | + flex-direction: column; |
| 43 | + align-items: center; |
| 44 | + justify-content: center; |
| 45 | + padding: 20px; |
| 46 | + } |
| 47 | + .code-container { |
| 48 | + width: 90%; |
| 49 | + max-width: 800px; |
| 50 | + background: rgba(0, 0, 0, 0.7); |
| 51 | + border: 1px solid #0f0; |
| 52 | + position: relative; |
| 53 | + } |
| 54 | + .code-header { |
| 55 | + padding: 15px; |
| 56 | + display: flex; |
| 57 | + justify-content: space-between; |
| 58 | + align-items: center; |
| 59 | + border-bottom: 1px solid #0f0; |
| 60 | + } |
| 61 | + .code-title { |
| 62 | + font-size: 20px; |
| 63 | + font-weight: bold; |
| 64 | + } |
| 65 | + .copy-btn { |
| 66 | + background: #111; |
| 67 | + color: #0f0; |
| 68 | + border: 1px solid #0f0; |
| 69 | + padding: 8px 15px; |
| 70 | + cursor: pointer; |
| 71 | + transition: all 0.3s; |
| 72 | + } |
| 73 | + .copy-btn:hover { |
| 74 | + background: #0f0; |
| 75 | + color: #000; |
| 76 | + } |
| 77 | + pre { |
| 78 | + padding: 20px; |
| 79 | + overflow-x: auto; |
| 80 | + tab-size: 4; |
| 81 | + max-height: 60vh; |
| 82 | + overflow-y: auto; |
| 83 | + } |
| 84 | + .nav-btn { |
| 85 | + position: fixed; |
| 86 | + bottom: 20px; |
| 87 | + right: 20px; |
| 88 | + z-index: 3; |
| 89 | + background: #111; |
| 90 | + color: #0f0; |
| 91 | + border: 1px solid #0f0; |
| 92 | + padding: 10px 20px; |
| 93 | + cursor: pointer; |
| 94 | + transition: all 0.3s; |
| 95 | + text-decoration: none; |
| 96 | + } |
| 97 | + .nav-btn:hover { |
| 98 | + background: #0f0; |
| 99 | + color: #000; |
| 100 | + } |
| 101 | + </style> |
| 102 | +</head> |
| 103 | +<body> |
| 104 | + <canvas id="matrix"></canvas> |
| 105 | + |
| 106 | + <header> |
| 107 | + <h1>挑战20学会5种算法</h1> |
| 108 | + <p>#3</p> |
| 109 | + </header> |
| 110 | + |
| 111 | + <div class="content"> |
| 112 | + <div class="code-container"> |
| 113 | + <div class="code-header"> |
| 114 | + <div class="code-title">插入排序+函数</div> |
| 115 | + <button class="copy-btn" onclick="copyCode()">复制代码</button> |
| 116 | + </div> |
| 117 | + <pre id="code-content">// 这里放置您的代码 |
| 118 | +function example() { |
| 119 | + console.log("这是示例代码"); |
| 120 | + return "Hello World!"; |
| 121 | +}</pre> |
| 122 | + </div> |
| 123 | + </div> |
| 124 | + |
| 125 | + <a href="blog.html" class="nav-btn">返回主页</a> |
| 126 | + |
| 127 | + <script> |
| 128 | + // 代码雨背景 |
| 129 | + const canvas = document.getElementById('matrix'); |
| 130 | + const ctx = canvas.getContext('2d'); |
| 131 | + |
| 132 | + function resizeCanvas() { |
| 133 | + canvas.width = window.innerWidth; |
| 134 | + canvas.height = window.innerHeight; |
| 135 | + } |
| 136 | + resizeCanvas(); |
| 137 | + window.addEventListener('resize', resizeCanvas); |
| 138 | + |
| 139 | + const chars = "01"; |
| 140 | + const fontSize = 14; |
| 141 | + const columns = Math.floor(canvas.width / fontSize); |
| 142 | + const drops = Array(columns).fill(0); |
| 143 | + |
| 144 | + function drawMatrix() { |
| 145 | + ctx.fillStyle = 'rgba(0, 0, 0, 0.05)'; |
| 146 | + ctx.fillRect(0, 0, canvas.width, canvas.height); |
| 147 | + |
| 148 | + ctx.fillStyle = '#0f0'; |
| 149 | + ctx.font = `${fontSize}px monospace`; |
| 150 | + |
| 151 | + for (let i = 0; i < drops.length; i++) { |
| 152 | + const text = chars[Math.floor(Math.random() * chars.length)]; |
| 153 | + ctx.fillText(text, i * fontSize, drops[i] * fontSize); |
| 154 | + |
| 155 | + if (drops[i] * fontSize > canvas.height && Math.random() > 0.975) { |
| 156 | + drops[i] = 0; |
| 157 | + } |
| 158 | + drops[i]++; |
| 159 | + } |
| 160 | + |
| 161 | + requestAnimationFrame(drawMatrix); |
| 162 | + } |
| 163 | + |
| 164 | + // 复制代码功能 |
| 165 | + function copyCode() { |
| 166 | + const codeBlock = document.getElementById('code-content'); |
| 167 | + const range = document.createRange(); |
| 168 | + range.selectNode(codeBlock); |
| 169 | + window.getSelection().removeAllRanges(); |
| 170 | + window.getSelection().addRange(range); |
| 171 | + document.execCommand('copy'); |
| 172 | + window.getSelection().removeAllRanges(); |
| 173 | + |
| 174 | + const btn = document.querySelector('.copy-btn'); |
| 175 | + btn.textContent = '已复制!'; |
| 176 | + setTimeout(() => { |
| 177 | + btn.textContent = '复制代码'; |
| 178 | + }, 2000); |
| 179 | + } |
| 180 | + |
| 181 | + // 启动动画 |
| 182 | + drawMatrix(); |
| 183 | + </script> |
| 184 | +</body> |
| 185 | +</html> |
0 commit comments