炫酷的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伪元素来创建两个相同的文本层叠在原始文本之上,分别应用了不同的动画和阴影效果。同时设置颜色和背景色与原始文本保持一致。最后,将两个动画应用到伪元素上,并设置动画参数,使其无限循环播放、线性变化,并在交替方向上反转动画。

相关推荐
百锦再2 分钟前
复杂查询中基于代价的连接条件下推实践与思考
前端
广州华水科技3 分钟前
如何实现高精度的单北斗GNSS位移监测系统安装?
前端
肉肉不吃 肉14 分钟前
Vue Router 路由模式
前端·javascript·vue.js
北寻北爱14 分钟前
Vue-Router
前端·javascript·vue.js
肉肉不吃 肉20 分钟前
什么是闭包
前端·javascript
窝子面24 分钟前
十六、按钮组件
前端
天天向上102424 分钟前
vue 页面内实现el-table和div自动滚动
前端·javascript·vue.js
前端老石人32 分钟前
HTML文档元素与元数据详解
前端·html
wing9836 分钟前
用 AI 实现图片懒加载,这也太简单了!
前端·vue.js·图片资源
sigernet1 小时前
Claude Code 不再推荐 npm 安装:官方改为 Native Installer
前端·npm·node.js