当前位置:首页 > CSS

css制作弹球

2026-02-12 21:12:21CSS

css制作弹球

使用CSS制作弹球效果

通过CSS动画和关键帧(@keyframes)可以创建简单的弹球效果。以下是实现方法:

css制作弹球

创建HTML结构

<div class="ball"></div>

添加基础CSS样式

.ball {
  width: 50px;
  height: 50px;
  background-color: #ff5252;
  border-radius: 50%;
  position: absolute;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
}

实现弹跳动画

@keyframes bounce {
  0% {
    bottom: 0;
    animation-timing-function: ease-out;
  }
  50% {
    bottom: 200px;
    animation-timing-function: ease-in;
  }
  100% {
    bottom: 0;
    animation-timing-function: ease-out;
  }
}

.ball {
  animation: bounce 1s infinite;
}

添加物理效果

通过调整动画时间函数和关键帧位置模拟真实弹跳:

@keyframes realisticBounce {
  0% {
    bottom: 0;
    animation-timing-function: cubic-bezier(0.1, 0.25, 0.1, 1);
  }
  15% {
    bottom: 300px;
    animation-timing-function: cubic-bezier(0.05, 0, 0.85, 0.05);
  }
  25% {
    bottom: 200px;
  }
  35% {
    bottom: 280px;
  }
  45% {
    bottom: 230px;
  }
  55% {
    bottom: 270px;
  }
  65% {
    bottom: 240px;
  }
  75% {
    bottom: 260px;
  }
  85% {
    bottom: 245px;
  }
  100% {
    bottom: 250px;
  }
}

添加阴影效果增强真实感

.ball::before {
  content: '';
  position: absolute;
  width: 100%;
  height: 10px;
  background: rgba(0, 0, 0, 0.1);
  border-radius: 50%;
  bottom: -5px;
  left: 0;
  transform: scaleX(0.8);
  animation: shadow 1s infinite;
}

@keyframes shadow {
  0%, 100% {
    transform: scaleX(0.8);
    opacity: 0.6;
  }
  50% {
    transform: scaleX(1.2);
    opacity: 0.3;
  }
}

完整示例代码

<!DOCTYPE html>
<html>
<head>
  <style>
    .ball {
      width: 50px;
      height: 50px;
      background: radial-gradient(circle at 30% 30%, #ff5252, #d50000);
      border-radius: 50%;
      position: absolute;
      bottom: 0;
      left: 50%;
      transform: translateX(-50%);
      animation: bounce 1s infinite;
      box-shadow: inset -5px -5px 10px rgba(0, 0, 0, 0.3);
    }

    .ball::before {
      content: '';
      position: absolute;
      width: 100%;
      height: 10px;
      background: rgba(0, 0, 0, 0.1);
      border-radius: 50%;
      bottom: -5px;
      left: 0;
      transform: scaleX(0.8);
      animation: shadow 1s infinite;
    }

    @keyframes bounce {
      0% {
        bottom: 0;
        animation-timing-function: ease-out;
      }
      50% {
        bottom: 200px;
        animation-timing-function: ease-in;
      }
      100% {
        bottom: 0;
        animation-timing-function: ease-out;
      }
    }

    @keyframes shadow {
      0%, 100% {
        transform: scaleX(0.8);
        opacity: 0.6;
      }
      50% {
        transform: scaleX(1.2);
        opacity: 0.3;
      }
    }
  </style>
</head>
<body>
  <div class="ball"></div>
</body>
</html>

这个实现包含了基本的弹跳动画、物理效果模拟和视觉增强效果。可以通过调整关键帧百分比、高度值和动画时间函数来改变弹跳的节奏和高度。

标签: 弹球css
分享给朋友:

相关文章

min.css制作

min.css制作

使用 min.css 制作轻量级样式 min.css 是一个极简的 CSS 框架,专注于轻量化和快速加载。以下是如何使用 min.css 进行开发的步骤。 引入 min.css 通过 CDN 直接引…

css制作流程图

css制作流程图

使用CSS制作流程图的方法 基础布局结构 采用HTML的<div>元素构建流程节点,结合CSS的flexbox或grid布局实现整体排列。节点间用伪元素或独立元素(如<span>…

css制作

css制作

CSS 基础语法 CSS(层叠样式表)用于描述HTML元素的样式。一个基本的CSS规则由选择器和声明块组成。选择器指定要样式化的HTML元素,声明块包含一个或多个属性-值对,用花括号 {} 包裹。…

css表格制作

css表格制作

CSS表格制作方法 使用CSS创建表格可以通过多种方式实现,以下是常见的几种方法: 使用HTML原生表格标签结合CSS样式 <table class="styled-table">…

css制作下拉菜单

css制作下拉菜单

使用纯CSS制作下拉菜单 通过HTML和CSS可以创建无需JavaScript的下拉菜单,主要利用:hover伪类和display属性控制显示隐藏。 HTML结构示例: <div class…

淘宝css导航栏制作

淘宝css导航栏制作

淘宝CSS导航栏制作 制作类似淘宝的导航栏需要关注几个关键点:结构清晰、响应式设计、悬停效果以及图标使用。以下是具体实现方法: HTML结构 <div class="nav-container…