炫酷的CSS样式—赛博朋克故障风

给字体加炫酷的效果,直接展示:

先贴代码

less 复制代码
<template>
  <div style="height: 200px;width: 800px;background-color: rgb(78, 33, 33);">
    <link href='https://fonts.googleapis.com/css?family=Varela' rel='stylesheet' type='text/css'>
  <div class="glitch" data-text="Hello,World">Hello,World</div> 
  </div>

</template>
<style scoped lang="scss">
.glitch{
  color:rgb(168, 37, 37);
  font-size:80px;
  position:relative;
  width:400px;
  margin:0 auto;
}
@keyframes noise-anim{
  $steps:20;
  @for $i from 0 through $steps{
    #{percentage($i * calc(1 / $steps))}{
      clip:rect(random(100)+px,9999px,random(100)+px,0);
    }
  }
}

@keyframes noise-anim-2{
  $steps:20;
  @for $i from 0 through $steps{
    #{percentage($i * calc(1 / $steps))}{
      clip:rect(random(100)+px,9999px,random(100)+px,0);
    }
  }
}
.glitch:after{
  content:attr(data-text);
  position:absolute;
  left:2px;
  text-shadow:-1px 0 red;
  top:0;
  color:rgb(168, 37, 37);
  background:rgb(78, 33, 33);
  overflow:hidden;
  clip:rect(0,900px,0,0); 
  animation:noise-anim 2s infinite linear alternate-reverse;
}
.glitch:before{
  content:attr(data-text);
  position:absolute;
  left:-2px;
  text-shadow:1px 0 blue; 
  top:0;
  color:rgb(168, 37, 37);
  background:rgb(78, 33, 33);
  overflow:hidden;
  clip:rect(0,900px,0,0); 
  animation:noise-anim-2 3s infinite linear alternate-reverse;
}
</style>

主要是用的CSS的@keyframes规则和伪元素(:after:before)来实现了闪烁效果。

首先.glitch类定义了字体颜色、字体大小、位置等基本样式,以及元素的宽度和居中对齐。然后通过两个不同的@keyframes规则来定义了两个动画效果,分别命名为noise-animnoise-anim-2。这两个动画采用Sass的循环语法,生成了多个关键帧(steps),在每个关键帧中通过clip属性设置元素的裁剪范围,实现随机的位移效果。再分别使用:after:before伪元素来创建两个相同的文本层叠在原始文本之上,分别应用了不同的动画和阴影效果。同时设置颜色和背景色与原始文本保持一致。最后,将两个动画应用到伪元素上,并设置动画参数,使其无限循环播放、线性变化,并在交替方向上反转动画。

相关推荐
huwuhang4 分钟前
跨平台电子书阅读器 | Readest最新版 安卓版+PC版全平台
android·前端·javascript
C澒4 分钟前
AI 生码:RAG 检索优化实现可评估、可回溯工程化
前端·ai编程
Shirley~~5 分钟前
力扣hot100:每日温度
开发语言·javascript·ecmascript
条tiao条6 分钟前
不止语法糖:TypeScript Set 与 Map 深度解析
前端·javascript·typescript
freewlt27 分钟前
React Server Components 深度解析:从原理到实战的完整指南
前端·javascript·react.js
zhensherlock1 小时前
Protocol Launcher 系列:1Writer iOS 上的 Markdown 文档管理
javascript·笔记·ios·typescript·node.js·iphone·ipad
ZC跨境爬虫1 小时前
Playwright进阶操作:鼠标拖拽与各类点击实战(含自定义拖拽实例)
前端·爬虫·python·ui
小江的记录本1 小时前
【RabbitMQ】RabbitMQ核心知识体系全解(5大核心模块:Exchange类型、消息确认机制、死信队列、延迟队列、镜像队列)
java·前端·分布式·后端·spring·rabbitmq·mvc
心静财富之门1 小时前
《前端零基础入门:HTML + CSS + JavaScript 全套速查表(详细版 + 实例)》
前端·javascript·python
星空1 小时前
前端--A_4--HTML表单
前端