CSS实现小火箭加载动画

CSS实现小火箭加载动画

效果展示

CSS 知识点

  • 灵活运用 animation 属性与 transform 实现小车和其他元素的动画效果

动画场景分析

从效果看,我们要实现这个动画效果的话,需要两个容器来支撑布局,一个底部渐变色的背景容器,另外一个是用于装载小火箭和云朵的容器,而装载小火箭和云朵的容器是需要设置超出隐藏元素的属性,这样我们才能让云朵不断执行动画。具体的动画场景分层如下:

整体页面布局

html 复制代码
<div class="loader">
  <!-- 小火箭和云朵容器 -->
  <div class="rocket">
    <i class="fa-solid fa-cloud" style="--i:0"></i>
    <i class="fa-solid fa-cloud" style="--i:1"></i>
    <i class="fa-solid fa-cloud" style="--i:2"></i>
    <i class="fa-solid fa-cloud" style="--i:3"></i>
    <i class="fa-solid fa-cloud" style="--i:4"></i>
    <i class="fa-solid fa-rocket"></i>
  </div>
  <!-- 渐变色背景容器 -->
  <span><i></i></span>
</div>

场景容器样式实现

css 复制代码
/* 控制渐变色容器大小,也是整个动画的容器 */
.loader span {
  position: relative;
  width: 250px;
  height: 250px;
  background: #eaeef0;
  border: 6px solid #eaeef0;
  border-radius: 50%;
  box-shadow: -8px -8px 15px rgba(255, 255, 255, 1), 8px 8px 25px rgba(0, 0, 0, 0.15);
  overflow: hidden;
}

/* 外层圆样式 */
.loader span::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  box-shadow: inset 10px 10px 20px rgba(0, 0, 0, 0.5), inset -5px -5px 15px rgba(255, 255, 255, 1);
}

/* 内层圆样式 */
.loader span::after {
  content: "";
  position: absolute;
  inset: 40px;
  background: #eaeef0;
  border: 3px solid #eaeef0;
  border-radius: 50%;
  box-shadow: -8px -8px 25px rgba(255, 255, 255, 1), 8px 8px 25px rgba(0, 0, 0, 0.15),
    inset 3px 3px 10px rgba(0, 0, 0, 0.15), inset -1px -1px 15px rgba(255, 255, 255, 1);
}

/* 背景颜色 */
.loader span i {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: linear-gradient(#42abff, #ff4f8b, #ffeb3b);
  /* 实现背景旋转动画 */
  animation: animate 1s linear infinite;
}

@keyframes animate {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}

小火箭样式实现

css 复制代码
.rocket {
  position: absolute;
  inset: 50px;
  z-index: 10;
  display: flex;
  justify-content: center;
  align-items: center;
  /* 设置装载小火箭容器超出部分隐藏 */
  overflow: hidden;
  border-radius: 50%;
}

.rocket .fa-rocket {
  position: absolute;
  color: #ff518c;
  font-size: 3.5em;
  -webkit-text-stroke: 2px #000;
  /* 小火箭加速动画 */
  animation: animateRocket 0.2s linear infinite;
}

@keyframes animateRocket {
  0%,
  100% {
    transform: translate(0px, 0px) rotate(-45deg);
  }
  50% {
    transform: translate(0, 3px) rotate(-45deg);
  }
}

完成上述代码后,效果如下图:

云朵样式实现

css 复制代码
.fa-cloud {
  position: absolute;
  top: calc(35px * var(--i));
  left: calc(45px * var(--i));
  font-size: 2em;
  color: #fff;
  -webkit-text-stroke: 2px #000;
  animation: animateClounds 1s linear infinite;
  /* 动画延迟 */
  animation-delay: calc(-0.5s * var(--i));
}

/* 云层动画 */
@keyframes animateClounds {
  0% {
    transform: translateY(calc(-35 * 5px));
  }
  100% {
    transform: translateY(calc(35 * 5px));
  }
}

完整代码下载

完整代码下载

相关推荐
我命由我1234525 分钟前
微信小程序 - 自定义实现分页功能
前端·微信小程序·小程序·前端框架·html·html5·js
程序员黄同学1 小时前
请谈谈 Vue 中的 key 属性的重要性,如何确保列表项的唯一标识?
前端·javascript·vue.js
繁依Fanyi1 小时前
巧妙实现右键菜单功能,提升用户操作体验
开发语言·前端·javascript·vue.js·uni-app·harmonyos
前端御书房1 小时前
前端防重复请求终极方案:从Loading地狱到精准拦截的架构升级
前端·javascript
web182854825121 小时前
nginx 部署前端vue项目
前端·vue.js·nginx
zy0101011 小时前
HTML标签
前端·css·html
程序员黄同学1 小时前
解释 Vue 中的虚拟 DOM,如何通过 Diff 算法最小化真实 DOM 更新次数?
开发语言·前端·javascript
蓝谷芮济2 小时前
二:前端发送POST请求,后端获取数据
前端
果粒chenl2 小时前
css+js提问
前端·javascript·css
memorycx2 小时前
Vue02
前端·javascript·vue.js