这位怪蜀黍 中午的时光真难熬!还好有你在!

博客美化,页首波浪

首先需要申请开通博客js权限

接着在页首html栏添加如下代码即可

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
<canvas id="canvas" style="position:absolute;top:0px;left:0px;z-index:1;"></canvas>
<script type="text/javascript">
 var canvas = document.getElementById('canvas');
 var ctx = canvas.getContext('2d');
 canvas.width = canvas.parentNode.offsetWidth;
 canvas.height = canvas.parentNode.offsetHeight;
 //如果浏览器支持requestAnimFrame则使用requestAnimFrame否则使用setTimeout
 window.requestAnimFrame = (function(){
 return window.requestAnimationFrame  ||
   window.webkitRequestAnimationFrame ||
   window.mozRequestAnimationFrame ||
   function( callback ){
    window.setTimeout(callback, 1000 / 60);
   };
 })();
 // 波浪大小
 var boHeight = canvas.height / 10;
 var posHeight = canvas.height / 1.2;
 //初始角度为0
 var step = 0;
 //定义三条不同波浪的颜色
 var lines = ["rgba(0,222,255, 0.2)",
     "rgba(157,192,249, 0.2)",
     "rgba(0,168,255, 0.2)"];
 function loop(){
  ctx.clearRect(0,0,canvas.width,canvas.height);
  step++;
  //画3个不同颜色的矩形
  for(var j = lines.length - 1; j >= 0; j--) {
   ctx.fillStyle = lines[j];
   //每个矩形的角度都不同,每个之间相差45度
   var angle = (step+j*50)*Math.PI/180;
   var deltaHeight = Math.sin(angle) * boHeight;
   var deltaHeightRight = Math.cos(angle) * boHeight;
   ctx.beginPath();
   ctx.moveTo(0, posHeight+deltaHeight);
   ctx.bezierCurveTo(canvas.width/2, posHeight+deltaHeight-boHeight, canvas.width / 2, posHeight+deltaHeightRight-boHeight, canvas.width, posHeight+deltaHeightRight);
   ctx.lineTo(canvas.width, canvas.height);
   ctx.lineTo(0, canvas.height);
   ctx.lineTo(0, posHeight+deltaHeight);
   ctx.closePath();
   ctx.fill();
  }
  requestAnimFrame(loop);
 }
 loop();
</script>

  

posted @   蟾宝  阅读(74)  评论(0编辑  收藏  举报
编辑推荐:
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
点击右上角即可分享
微信分享提示