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);
}

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

相关推荐
snow@li8 小时前
html5:拖放 / demo / 拖放事件(Drag Events)/ DataTransfer 对象方法
前端·html·拖放
cdming9 小时前
微软Win11双AI功能来袭:“AI管家”+聊天机器人重构桌面交互体验
人工智能·microsoft·机器人
Dragonir11 小时前
React+Three.js 实现 Apple 2025 热成像 logo
前端·javascript·html·three.js·页面特效
aichitang202412 小时前
欧拉拓扑学公式:几何与拓扑的交汇
html·拓扑学
Larry_Yanan14 小时前
QML学习笔记(四十三)QML与C++交互:上下文属性暴露
c++·笔记·qt·学习·ui·交互
urhero15 小时前
工作事项管理小工具——HTML版
前端·html·实用工具·工作事项跟踪·任务跟踪小工具·本地小程序
top_designer17 小时前
告别“静态”VI手册:InDesign与AE打造可交互的动态品牌规范
设计模式·pdf·交互·vi·工作流·after effects·indesign
詩句☾⋆᭄南笙18 小时前
HTML的盒子模型
前端·html·盒子模型
嵌入式学习和实践18 小时前
C# WinForms 多窗口交互通信的示例-主窗口子窗口交互通信
c#·交互·主窗口-子窗口通信
Southern Wind20 小时前
Vue 3 多实例 + 缓存复用:理念及实践
前端·javascript·vue.js·缓存·html