10个常见渐变交互效果

1、透明度渐变背景交互

go 复制代码
<div class="fade-background"></div>
go 复制代码
Copy
.fade-background {
  width: 200px;
  height: 200px;
  background: linear-gradient(to bottom, rgba(255, 0, 0, 0), rgba(255, 0, 0, 1));
  transition: background 0.5s ease;
}

.fade-background:hover {
  background: linear-gradient(to bottom, rgba(255, 0, 0, 1), rgba(255, 0, 0, 0));
}

说明:这个案例创建了一个矩形区域,当鼠标悬停时,背景从完全透明到纯红色渐变,再从纯红色渐变到完全透明。

2、渐变背景文字交互

go 复制代码
<h1 class="gradient-text">Hello, World!</h1>
go 复制代码
.gradient-text {
  background: linear-gradient(to right, red, blue);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  transition: background 0.5s ease;
}

.gradient-text:hover {
  background: linear-gradient(to right, blue, red);
}

说明:这个案例创建了一个标题,当鼠标悬停时,文字颜色从红色渐变到蓝色,并且背景渐变也相应改变。

3、鼠标跟随渐变交互

go 复制代码
<div class="follow-gradient"></div>
go 复制代码
.follow-gradient {
  width: 200px;
  height: 200px;
  background: linear-gradient(to right, red, blue);
  position: relative;
}

.follow-gradient:before {
  content: "";
  width: 20px;
  height: 20px;
  background: white;
  border-radius: 50%;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  transition: background 0.5s ease;
}

.follow-gradient:hover:before {
  background: linear-gradient(to right, blue, red);
}

说明:这个案例创建了一个正方形区域,在其中心有一个小白点。当鼠标悬停时,小白点的颜色从白色渐变到蓝色和红色。

4、渐变按钮交互

go 复制代码
<button class="gradient-button">Click Me</button>
go 复制代码
.gradient-button {
  background: linear-gradient(to right, red, blue);
  border: none;
  color: white;
  padding: 10px 20px;
  position: relative;
  overflow: hidden;
  transition: transform 0.5s ease;
}

.gradient-button:after {
  content: "";
  background: rgba(255, 255, 255, 0.5);
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  transform: skewX(45deg);
  transition: transform 0.5s ease;
}

.gradient-button:hover {
  transform: scale(1.2);
}

.gradient-button:hover:after {
  left: 100%;
}

说明:这个案例创建了一个渐变按钮,当鼠标悬停时,按钮会放大并展示一个斜切的渐变背景。

5、渐变边框动画交互

go 复制代码
<div class="border-animation"></div>
go 复制代码
@keyframes border-animation {
  0% {
    border-color: red;
  }
  50% {
    border-color: blue;
  }
  100% {
    border-color: red;
  }
}

.border-animation {
  width: 200px;
  height: 200px;
  border: 2px solid red;
  animation: border-animation 3s infinite;
  }

说明:这个案例创建了一个矩形区域,边框颜色会在红色和蓝色之间循环变化,形成一个动画效果。

6、文字渐变动画交互

go 复制代码
<h1 class="text-animation">Hello, World!</h1>
go 复制代码
@keyframes text-animation {
  0% {
    color: red;
  }
  50% {
    color: blue;
  }
  100% {
    color: red;
  }
}

.text-animation {
  animation: text-animation 3s infinite;
}

说明:这个案例创建了一个标题,文字颜色会在红色和蓝色之间循环变化,形成一个动画效果。

7、渐变阴影交互

go 复制代码
<div class="gradient-shadow"></div>
go 复制代码
.gradient-shadow {
  width: 200px;
  height: 200px;
  background: red;
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
  transition: box-shadow 0.5s ease;
}

.gradient-shadow:hover {
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.2), 0 0 20px rgba(0, 0, 0, 0.3), 0 0 30px rgba(0, 0, 0, 0.4);
}

说明:这个案例创建了一个矩形区域,当鼠标悬停时,阴影效果从浅到深渐变,形成一个立体感。

8、渐变背景缩放交互

go 复制代码
<div class="scale-background"></div>
go 复制代码
.scale-background {
  width: 200px;
  height: 200px;
  background: linear-gradient(to right, red, blue);
  transition: background-size 0.5s ease;
}

.scale-background:hover {
  background-size: 200% 200%;
}

说明:这个案例创建了一个矩形区域,当鼠标悬停时,背景渐变会放大到原来的两倍大小。

9、渐变背景旋转交互

go 复制代码
<div class="rotate-background"></div>
go 复制代码
.rotate-background {
  width: 200px;
  height: 200px;
  background: linear-gradient(to right, red, blue);
  transition: transform 0.5s ease;
}

.rotate-background:hover {
  transform: rotate(180deg);
}

说明:这个案例创建了一个矩形区域,当鼠标悬停时,背景渐变会顺时针旋转180度。

10、渐变背景模糊交互

go 复制代码
<div class="blur-background"></div>
go 复制代码
.blur-background {
  width: 200px;
  height: 200px;
  background: linear-gradient(to right, red, blue);
  transition: filter 0.5s ease;
}

.blur-background:hover {
  filter: blur(5px);
}

说明:这个案例创建了一个矩形区域,当鼠标悬停时,背景渐变会模糊化,形成一个柔和的效果。

相关推荐
BIBABULALA1 小时前
Mini Virtual Machine — 可视化虚拟机模拟器(91行)
前端·css·css3
gp3210261 小时前
MSSQL2022的一个错误:未在本地计算机上注册“Microsoft.ACE.OLEDB.16.0”提供程序
数据库·microsoft
badhope2 小时前
C语言二级考点全解析与真题精讲
c语言·开发语言·c++·人工智能·python·microsoft·职场和发展
召田最帅boy2 小时前
使用自定义图片作为Emoji表情的技术实现
数据库·html
Access开发易登软件5 小时前
在 Access 实现标签输入控件:VBA + HTML 混合开发实战
前端·数据库·信息可视化·html·excel·vba·access
梓贤Vigo5 小时前
【Axure教程】拖动分组
交互·产品经理·axure·原型·教程
cy_cy0026 小时前
当历史遇见光影:投影创新点亮文化艺术展览
科技·3d·人机交互·交互·软件构建
小鹿软件办公7 小时前
Windows 11 更新 C 盘无法访问?微软澄清问题出在三星身上
microsoft·三星笔记本c盘无法访问
aXin_li7 小时前
从原子化到工程化:Tailwind CSS 的深层价值与实践思考
前端·css
放下华子我只抽RuiKe57 小时前
智聊机器人进阶:从 API 调试到全功能交互界面的完美落地
开发语言·人工智能·python·机器学习·分类·机器人·交互