1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189
| <!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Hexo 博客雪花效果预览</title> <style> body { margin: 0; padding: 0; background-color: #2c3e50; color: #ecf0f1; font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; height: 100vh; overflow-x: hidden; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.content { z-index: 10; background: rgba(255, 255, 255, 0.1); padding: 40px; border-radius: 15px; backdrop-filter: blur(5px); max-width: 600px; text-align: center; box-shadow: 0 4px 15px rgba(0,0,0,0.3); }
h1 { font-weight: 300; margin-bottom: 20px; }
p { line-height: 1.6; }
.highlight { color: #e74c3c; font-weight: bold; }
.mock-post { margin-top: 20px; text-align: left; font-size: 0.9em; color: #bdc3c7; } </style> </head> <body>
<div class="content"> <h1>❄️ 淡淡的雪花效果 ❄️</h1> <p>这就是应用到您博客后的样子。</p> <p>雪花具有随机的大小、透明度和飘落速度。</p> <p>鼠标悬停在此处,<span class="highlight">雪花不会阻挡点击</span> (Pointer Events None)。</p> <div class="mock-post"> <hr style="border-color: rgba(255,255,255,0.1);"> <p><strong>示例文章标题</strong></p> <p>这是一段示例文本。雪花应该在背景中轻轻飘落,不影响阅读体验。代码使用了 HTML5 Canvas,性能消耗极低。</p> </div> </div>
<script> (function() { const config = { snowFlakeCount: 60, maxRadius: 12, minRadius: 8, minOpacity: 0.3, maxOpacity: 0.8, minSpeed: 0.5, maxSpeed: 1.5, zIndex: 999999, color: "255, 255, 255" };
const canvas = document.createElement('canvas'); const ctx = canvas.getContext('2d'); canvas.style.position = 'fixed'; canvas.style.top = '0'; canvas.style.left = '0'; canvas.style.width = '100%'; canvas.style.height = '100%'; canvas.style.zIndex = config.zIndex; canvas.style.pointerEvents = 'none'; document.body.appendChild(canvas);
let width, height; let snowflakes = [];
function resize() { width = window.innerWidth; height = window.innerHeight; canvas.width = width; canvas.height = height; } window.addEventListener('resize', resize); resize();
const snowChars = ['❄', '❅', '❆'];
class Snowflake { constructor() { this.reset(true); }
reset(initial = false) { this.x = Math.random() * width; this.y = initial ? Math.random() * height : -20; this.size = Math.random() * (config.maxRadius - config.minRadius) + config.minRadius; this.speed = Math.random() * (config.maxSpeed - config.minSpeed) + config.minSpeed; this.opacity = Math.random() * (config.maxOpacity - config.minOpacity) + config.minOpacity; this.drift = Math.random() * 2 - 1; this.rotation = Math.random() * Math.PI * 2; this.spin = (Math.random() - 0.5) * 0.05; this.char = snowChars[Math.floor(Math.random() * snowChars.length)]; }
update() { this.y += this.speed; this.x += this.drift * 0.5; this.rotation += this.spin;
if (this.y > height + 20) { this.reset(); } if (this.x > width + 20) { this.x = -20; } else if (this.x < -20) { this.x = width + 20; } }
draw() { ctx.save(); ctx.translate(this.x, this.y); ctx.rotate(this.rotation);
ctx.font = `${this.size}px Arial, sans-serif`; ctx.fillStyle = `rgba(${config.color}, ${this.opacity})`; ctx.textAlign = 'center'; ctx.textBaseline = 'middle'; ctx.fillText(this.char, 0, 0);
ctx.restore(); } }
for (let i = 0; i < config.snowFlakeCount; i++) { snowflakes.push(new Snowflake()); }
function animate() { ctx.clearRect(0, 0, width, height); snowflakes.forEach(flake => { flake.update(); flake.draw(); }); requestAnimationFrame(animate); } animate(); })(); </script>
</body> </html>
|