网页常用动效大全

在网站制作中,好看、高级、不卡顿的动效,本质都是简单 CSS + 少量 JS实现。绝大多数商业网站 95% 的动效,不需要复杂动画引擎,只用原生代码即可实现。

本文整理前端开发最高频、最实用、适配所有网站的网页动效,每一种效果都附带完整可直接复制的代码,开箱即用,兼容 PC/移动端,性能稳定无卡顿。


一、网页动效核心基础知识(必看)

网页动画只有两种核心,看懂即可驾驭所有动效:

  • transition 过渡动画:状态变化动画(hover、点击、显隐)
  • @keyframes 关键帧动画:持续循环、入场、动态效果

行业通用标准参数(所有动效统一节奏):

  • 时长:常规 0.2s–0.3s,入场 0.5s
  • 缓动:ease / ease-in-out(柔和高级)
  • 原则:小幅度、慢节奏、不闪烁、不抖动

二、高频动效 1:按钮 Hover 高级动效(全站必备)

适用:所有按钮、卡片、可点击区块,网页最基础也最提升质感的动效。

效果说明

鼠标悬浮:轻微上浮、放大、阴影加深,自然高级不浮夸。

完整代码

<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<title>按钮Hover动效</title>
<style>
.btn{
  display: inline-block;
  padding: 12px 30px;
  background: #2468f2;
  color: #fff;
  border-radius: 6px;
  text-decoration: none;
  /* 统一过渡属性 */
  transition: all 0.3s ease;
}
.btn:hover{
  transform: translateY(-3px) scale(1.03);
  box-shadow: 0 8px 20px rgba(36,104,242,0.3);
}
.btn:active{
  /* 点击按下效果 */
  transform: translateY(0) scale(1);
}
</style>
</head>
<body>
<a href="#" class="btn">立即咨询</a>
</body>
</html>

三、高频动效 2:卡片悬浮渐变动效(企业站/产品列表)

适用:产品卡片、案例卡片、新闻列表、服务模块,商业网站使用率极高。

效果说明

悬浮变色、阴影扩散、轻微上浮,模块层级瞬间拉开。

完整代码

<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<title>卡片悬浮动效</title>
<style>
.card{
  width: 300px;
  padding: 30px;
  background: #fff;
  border-radius: 10px;
  box-shadow: 0 2px 10px rgba(0,0,0,0.08);
  transition: all 0.3s ease;
}
.card:hover{
  transform: translateY(-5px);
  box-shadow: 0 15px 30px rgba(0,0,0,0.12);
}
</style>
</head>
<body>
<div class="card">
  <h3>服务模块标题</h3>
  <p>网页卡片动效演示内容</p>
</div>
</body>
</html>

四、高频动效 3:元素淡入入场动效(滚动可视区触发)

适用:首页所有模块、图文区块、产品展示,解决页面死板、一次性加载的问题。

效果说明

页面滚动到元素位置,元素从下方滑入、淡入显示。

完整代码(CSS+少量JS,可直接复用)

<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<title>滚动入场动效</title>
<style>
.box{
  width: 300px;
  height: 200px;
  background: #2468f2;
  margin: 500px auto;
  border-radius: 8px;
  /* 初始状态:透明+下移 */
  opacity: 0;
  transform: translateY(30px);
  transition: all 0.6s ease;
}
/* 滚动后添加的激活类 */
.box.show{
  opacity: 1;
  transform: translateY(0);
}
</style>
</head>
<body>
<div class="box"></div>

<script>
// 获取元素
const animateBox = document.querySelector('.box');
// 滚动监听
window.addEventListener('scroll',function(){
  let top = animateBox.getBoundingClientRect().top;
  let windowHeight = window.innerHeight;
  // 进入可视区域则显示动画
  if(top < windowHeight - 50){
    animateBox.classList.add('show');
  }
})
</script>
</body>
</html>

五、高频动效 4:Tab选项卡下划线跟随动效

适用:产品分类、新闻标签、内容切换模块,高级且百搭。

完整代码

<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<title>Tab下划线跟随动效</title>
<style>
.tab{
  display: flex;
  gap: 40px;
  position: relative;
}
.tab-item{
  cursor: pointer;
  padding: 10px 0;
}
/* 下划线容器 */
.tab-line{
  position: absolute;
  bottom: 0;
  left: 0;
  height: 3px;
  background: #2468f2;
  border-radius: 3px;
  transition: all 0.3s ease;
  width: 60px;
}
</style>
</head>
<body>
<div class="tab">
  <div class="tab-item" onmouseover="moveLine(0)">首页</div>
  <div class="tab-item" onmouseover="moveLine(60)">关于我们</div>
  <div class="tab-item" onmouseover="moveLine(120)">案例展示</div>
  <div class="tab-line"></div>
</div>

<script>
function moveLine(leftVal){
  document.querySelector('.tab-line').style.left = leftVal + 'px';
}
</script>
</body>
</html>

六、高频动效 5:图片光影扫过动效(高端质感)

适用:LOGO、产品图、官网banner、高端模块点缀,极简高级。

完整代码

<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<title>光影扫过动效</title>
<style>
.shine-box{
  width: 300px;
  height: 180px;
  background: #111;
  border-radius: 8px;
  position: relative;
  overflow: hidden;
}
.shine-box::after{
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg,transparent,rgba(255,255,255,0.15),transparent);
  animation: shine 2.5s infinite linear;
}
@keyframes shine{
  0%{left: -100%;}
  100%{left: 100%;}
}
</style>
</head>
<body>
<div class="shine-box"></div>
</body>
</html>

七、高频动效 6:轻微浮动动画(装饰点缀)

适用:图标、装饰元素、LOGO,低频率循环,不刺眼。

完整代码

<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<title>浮动动效</title>
<style>
.float{
  width: 100px;
  height: 100px;
  background: #2468f2;
  border-radius: 50%;
  animation: float 3s ease-in-out infinite;
}
@keyframes float{
  0%,100%{transform: translateY(0);}
  50%{transform: translateY(-8px);}
}
</style>
</head>
<body>
<div class="float"></div>
</body>
</html>

八、高频动效 7:弹窗缩放弹出/关闭动效

适用:登录弹窗、提示弹窗、详情弹窗,解决弹窗生硬弹出问题。

完整代码

<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<title>弹窗动效</title>
<style>
.popup{
  width: 400px;
  padding: 40px;
  background: #fff;
  border-radius: 10px;
  /* 初始状态 */
  opacity: 0;
  transform: scale(0.9);
  transition: all 0.3s ease;
  visibility: hidden;
}
.popup.show{
  opacity: 1;
  transform: scale(1);
  visibility: visible;
}
</style>
</head>
<body>
<button onclick="document.querySelector('.popup').classList.add('show')">打开弹窗</button>
<div class="popup">弹窗内容区域</div>
</body>
</html>

九、网页动效统一落地规范(开发必遵守)

  • 优先 CSS:90%场景用 CSS 动画,性能远高于 JS
  • 幅度克制:缩放不超1.05倍,位移不超10px,拒绝浮夸
  • 时长统一:交互0.3s、入场0.6s、点击0.2s
  • 禁止滥用:正文文字区域不做动画,避免干扰阅读
  • 移动端适配:移动端取消复杂视差、循环动画,保证流畅度

十、总结

商业网站所有高级动效,都是由过渡动画 + 关键帧动画 + 简单JS触发组合而成。本文 7 种动效,覆盖企业官网、营销网站、个人网站、后台系统的绝大多数开发场景,代码轻量化、无依赖、可直接复制粘贴使用,是网页设计与网站制作的实用动效手册。