canvas实现文字滴血液态动画效果代码

代码语言:html

所属分类:动画

代码描述:canvas实现文字滴血液态动画效果代码

代码标签: canvas 文字 滴血 液态 动画

下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开

<!DOCTYPE html>
<html lang="en" >
<head>
  <meta charset="UTF-8">
  <style>
      @import url("https://fonts.googleapis.com/css2?family=Black+Han+Sans&display=swap");
*, *::before, *::after {
  padding: 0;
  margin: 0 auto;
  box-sizing: border-box;
}

body {
  background-color: #000;
  color: #fff;
  min-height: 100vh;
  display: grid;
  place-items: center;
  overflow: hidden;
}

.container {
  position: relative;
  width: 95%;
  max-width: 1200px;
  aspect-ratio: 3/2;
  overflow: hidden;
}

canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
}
canvas:nth-child(1) {
  background-color: #000;
  filter: contrast(15);
}
canvas:nth-child(2) {
  translate: 3% 2%;
  opacity: 0.5;
}
  </style>

</head>
<body>

<div class="container">
  <canvas></canvas>
  <canvas></canvas> 
</div>
<script  >
      console.clear();

const cw = 1200;
const ch = 800;
let imageData;

const canvas = [...document.querySelectorAll('canvas')];

const ctx = canvas.map(c => {
  c.width = cw;
  c.height = ch;
  return c.getContext("2d");
});
                       
const offscreenCanvas = new OffscreenCanvas(cw, ch);
const osCtx = offscreenCanvas.getContext("2d");

[osCtx, ...Object.values(ctx)].forEach(thisCtx => {
  thisCtx.font = '500px Black Han Sans';
  thisCtx.textAlign = "center";
  thisCtx.textBaseline = "middle";
})

osCtx.clearRect(0, 0, cw, ch);
osCtx.fillStyle = &q.........完整代码请登录后点击上方下载按钮下载查看

网友评论0