数字科技背景动画效果代码
代码语言:html
所属分类:背景
代码描述:数字科技背景动画效果代码
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html> <html lang="en" > <head> <meta charset="UTF-8"> <link href="https://fonts.googleapis.com/css2?family=Roboto:wght@100&display=swap" rel="stylesheet"> <style> * { padding: 0; margin: 0; box-sizing: border-box; font-family: "Roboto"; font-weight: 100; } body { font-size: 18px; color: hsla(210deg, 100%, 100%, 1); width: 100vw; height: 100vh; display: flex; justify-content: center; align-items: center; } h1 { text-transform: uppercase; letter-spacing: 1.5em; font-size: clamp(1em, 5vw, 4em); animation: breath 10000ms ease-in-out infinite alternate; } h1 > .last { letter-spacing: 0; } @keyframes breath { 0% { transform: scale(1); } 100% { transform: scale(1.1); } } canvas { position: absolute; top: 0; left: 0; margin: 0; padding: 0; background-color: hsla(240deg, 20%, 20%, 1); } </style> </head> <body> <canvas id="lines"></canvas> <h1>The futur<span class="last">e</span></h1> <script> (function () { const canvas = document.getElementById("lines"); const ctx = canvas.getContext("2d"); let width; let height; class Line { constructor(origin, size, length, color, style = "pattern") { this.size = size; this.origin = origin; this.length = length; this.color = color; this.style = style; this.origin = `M${origin.x},${origin.y}`; this.offSet = 0; this.line = null; this.offSetSpeed = length / size; } getColorString() { return `hsla(${this.color.h}deg,${this.color.s}%,${this.color.l}%,${this.color.a})`; } generators() { return [ { line: `h${this.size}`, mag: this.size }, { line: `h-${this.size}`, mag: this.size }, { line: `v${this.size}`, mag: this.size }, { line: `v-${this.size}`, mag: this.size }, { line: `l${this.size},${this.size}`, mag: Math.hypot(this.size, this.size) }, { line: `l${this.size}-${this.size}`, mag: Math.hypot(this.size, this.size) }, { line: `l-${this.size},${this.size}`, mag: Math.hypot(this.size, this.size) }, { line: `l-${this.size}-${this.size}`, mag: Math.hypot(this.size, this.size) } ]; } generate() { let segments = this.generators(this.size); let path = this.origin; let mag = 0; let fragment; let i; for (i = 0; i < this.length; i += 1) { fragment = segments[(Math.random() * segments.length) | 0]; path += ` ${fragment.line}`; mag += fragment.mag; } this.line = { path, mag }; return this; } renderStyle(style) { if (style === "glitches") { ctx.lineDashOffset = this.line.mag + this.offSet; ctx.setLineDash([ this.size ** 1.5, (this.line.mag / this.length) * this.size ** 2 ]); .........完整代码请登录后点击上方下载按钮下载查看
网友评论0