CSS 实现丝滑动画

效果展示

CSS 知识点

  • animation 综合运用

页面整体布局

html 复制代码
<div class="box">
  <div class="circle"></div>
</div>

编写基础样式

css 复制代码
.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);
}

编写小球样式

css 复制代码
.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;
}

编写动画

css 复制代码
.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 定时刷新背景

javascript 复制代码
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);

完整代码下载

完整代码下载

相关推荐
Redstone Monstrosity3 分钟前
字节二面
前端·面试
东方翱翔10 分钟前
CSS的三种基本选择器
前端·css
Fan_web32 分钟前
JavaScript高级——闭包应用-自定义js模块
开发语言·前端·javascript·css·html
yanglamei196240 分钟前
基于GIKT深度知识追踪模型的习题推荐系统源代码+数据库+使用说明,后端采用flask,前端采用vue
前端·数据库·flask
千穹凌帝41 分钟前
SpinalHDL之结构(二)
开发语言·前端·fpga开发
dot.Net安全矩阵1 小时前
.NET内网实战:通过命令行解密Web.config
前端·学习·安全·web安全·矩阵·.net
Hellc0071 小时前
MacOS升级ruby版本
前端·macos·ruby
前端西瓜哥1 小时前
贝塞尔曲线算法:求贝塞尔曲线和直线的交点
前端·算法
又写了一天BUG1 小时前
npm install安装缓慢及npm更换源
前端·npm·node.js
cc蒲公英1 小时前
Vue2+vue-office/excel 实现在线加载Excel文件预览
前端·vue.js·excel