CSS 实现丝滑动画

效果展示

在这里插入图片描述

CSS 知识点

  • animation 综合运用

页面整体布局

<div class="box">
  <div class="circle"></div>
</div>

编写基础样式

.box {
   
  position: relative;
  width: 400px;
  height: 400px;
  border: 80px solid transparent;
  border-left: 80px solid #fff5;
  border-bottom: 80px solid #fff5;
  border-radius: 50%;
  transform: rotate(-45deg);
}

.box::after {
   
  content: "";
  position: absolute;
  top: -13px;
  left: -34px;
  width: 80px;
  height: 40px;
  background: #fff;
  border-radius: 50%;
  transform: rotate(45deg);
}

.box::before {
   
  content: "";
  position: absolute;
  top: 214px;
  right: -33px;
  width: 80px;
  height: 40px;
  background: #fff;
  border-radius: 50%;
  transform: rotate(45deg);
}

编写小球样式

.circle {
   
  position: absolute;
  top: 65px;
  left: -65px;
  width: 70px;
  height: 70px;
  background: #fff;
  border-radius: 50%;
  box-shadow: inset 0 5px 20px rgba(0, 0, 0, 0.5);
  z-index: 10000;
  transform-origin: 200px;
}

编写动画

.box {
   
  animation: animate 2s linear infinite;
}

/* 第三阶段 */
@keyframes animate {
   
  0%,
  100% {
   
    transform: rotate(333deg);
  }
  50% {
   
    transform: rotate(290deg);
  }
}

.circle {
   
  animation: animateBall 2s linear infinite;
}

@keyframes animateBall {
   
  0%,
  100% {
   
    transform: rotate(45deg);
  }
  50% {
   
    transform: rotate(225deg);
  }
}

编写 JS 定时刷新背景

function changeBg() {
   
  let r = Math.floor(Math.random() * 255);
  let g = Math.floor(Math.random() * 255);
  let b = Math.floor(Math.random() * 255);

  document.body.style.backgroundColor = `rgba(${
     r}, ${
     g}, ${
     b})`;
}

setInterval(() => {
   
  changeBg();
}, 4000);

完整代码下载

完整代码下载

相关推荐

  1. css去除滑动

    2023-12-11 09:30:05       16 阅读

最近更新

  1. TCP协议是安全的吗?

    2023-12-11 09:30:05       18 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2023-12-11 09:30:05       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2023-12-11 09:30:05       18 阅读
  4. 通过文章id递归查询所有评论(xml)

    2023-12-11 09:30:05       20 阅读

热门阅读

  1. leetcode每日一题38

    2023-12-11 09:30:05       40 阅读
  2. 在Vue 3中如何禁止网页返回到上一页

    2023-12-11 09:30:05       28 阅读
  3. Python基础期末复习 新手

    2023-12-11 09:30:05       40 阅读
  4. 程序员常用英文单词

    2023-12-11 09:30:05       25 阅读
  5. android-xml语法

    2023-12-11 09:30:05       34 阅读
  6. MapReduce

    2023-12-11 09:30:05       25 阅读
  7. 华为鸿蒙HarmonyOS应用开发者高级认证试题及答案

    2023-12-11 09:30:05       143 阅读
  8. web项目创建流程框架

    2023-12-11 09:30:05       42 阅读
  9. 《C++新经典设计模式》之第15章 适配器模式

    2023-12-11 09:30:05       30 阅读
  10. C++(14):获取类型在tuple中的索引

    2023-12-11 09:30:05       32 阅读