肖强的博客 肖强的博客
Home
Guide
Web Document
  • Plugins
  • Case
  • Animation
Components
  • Categories
  • Tags
  • Archives
Website Tools

xiaoQiang

因为爱所以爱
Home
Guide
Web Document
  • Plugins
  • Case
  • Animation
Components
  • Categories
  • Tags
  • Archives
Website Tools
  • CSS

    • 00.CSS教程和技巧收藏
    • 01.flex布局语法
    • 02.flex布局案例-基础
    • 03.flex布局案例-骰子
    • 04.flex布局案例-圣杯布局
    • 05.flex布局案例-网格布局
    • 06.flex布局案例-输入框布局
    • 07.CSS3之transition过渡
    • 08.CSS3之animation动画
      • 09.「布局技巧」图片未加载前自动撑开元素高度
      • 10.文字在一行或多行时超出显示省略号
      • 11.从box-sizing属性入手,了解盒子模型
      • 12.水平垂直居中的几种方式-案例
      • 13.如何根据系统主题自动响应CSS深色模式
      • 14.「css技巧」使用hover和attr()定制悬浮提示
      • 15.CSS-function汇总
    • views
    xiaoQiang
    2019-12-25

    CSS3之animation动画

    # CSS3之animation动画

    可用F12开发者工具查看元素及样式,可打开codepen在线编辑代码。

    旋转动画1
    旋转动画2

    弹性动画
    曲线弹性

    [vanilla]

    <html>
      <div class="animationBox">
        <div class="rotate">旋转动画1</div>
        <div class="play">
          <div class="img">旋转动画2</div>
          <span><p class="p2"></p></span>
          <span><p></p></span>
          <span><p></p></span>
          <span><p class="p2"></p></span>
        </div>
        <div class="elasticity">弹性动画</div>
        <div class="elasticity2">曲线弹性</div>
      </div>
    </html>
    
    <style>
      .animationBox{overflow: hidden;}
      .animationBox>div{
        width: 100px;height: 100px;background: #eee;border-radius: 50%;text-align: center;line-height: 100px;margin: 30px;float:left;
      }
      .rotate{
        animation: rotate 5s linear infinite
      }
      .rotate:hover{ animation-play-state: paused}
      @keyframes rotate {
        0%{transform: rotate(0);}
      100%{transform: rotate(360deg);}
      }
      .animationBox>.play {
        position: relative;
        margin: 50px 30px;
        background:none;
      }
      .play .img{
        position: absolute;
        top: 0;
        left:0;
        z-index: 1;
        width: 100px;height: 100px; background: #eee;
        border-radius: 50%;
    
        animation: rotate 5s linear infinite
      }
      .play span {
        position: absolute;
        top: 1px;
        left:1px;
        z-index: 0;
        display: block;
        width: 96px;
        height: 96px;
        border: 1px solid #999;
        border-radius: 50%;
      }
      .play span p{display: block;width: 4px;height: 4px;background: #000;margin: -2px 0 0 50%;border-radius: 50%;opacity: 0.5;}
      .play span .p2{margin: 50% 0 0 -2px;}
      .play span{
        animation: wave 5s linear infinite
      }
      .play>span:nth-child(3){
        /* 延迟时间 */
        animation-delay:1s; 
      }
      .play>span:nth-child(4){
        animation-delay:2.2s;
      }
      .play>span:nth-child(5){
        animation-delay:3.8s;
      }
      
      @keyframes wave {
        0%
        {
          transform:scale(1) rotate(360deg);
          opacity: 0.8;
        }
      100%
        {
          transform:scale(1.8) rotate(0deg);
          opacity: 0;
        }
      }
    
    
      .elasticity{
        /* 参数说明
          动画名称 花费时间 贝塞尔曲线 延迟开始时间 播放次数n|infinite  是否反向播放动画
        */
        animation: elasticity 1s linear 2s infinite
      }
      
      @keyframes elasticity{
        0%{
          transform: scale(0);
        }
        60%{
          transform: scale(1.1);
        }
        90%{
          transform: scale(1);
        }
      }
      
    
      .elasticity2{
        /**
        贝塞尔曲线 cubic-bezier(x1,y1,x2,y2)
    
        通过调整贝塞尔曲线可以设置出多种动画效果,比如反弹效果等
        X轴的范围是0~1,Y轴的取值没有规定,但是也不宜过大
        直线:linear,即cubic-bezier(0,0,1,1)
    
        贝塞尔曲线在线工具:https://cubic-bezier.com/#.17,.67,.83,.67
          */
        animation: elasticity2 1s cubic-bezier(.39,.62,.74,1.39) 2s infinite
      }
      @keyframes elasticity2{
        0%{
          transform: scale(0);
        }
        90%{
          transform: scale(1);
        }
      }
    </style>
    
    显示代码 复制代码 复制代码

    # 贝塞尔曲线 cubic-bezier(x1,y1,x2,y2)

    通过调整贝塞尔曲线可以设置出多种动画效果,比如反弹效果等 X轴的范围是0~1,Y轴的取值没有规定,但是也不宜过大。 如:直线linear,即cubic-bezier(0,0,1,1)

    贝塞尔曲线在线工具:https://cubic-bezier.com/#.17,.67,.83,.67 (opens new window)

    参考:https://www.w3school.com.cn/css3/index.asp (opens new window)

    #CSS
    上次更新: 2021-10-06 15:11:51
    07.CSS3之transition过渡
    09.「布局技巧」图片未加载前自动撑开元素高度

    ← 07.CSS3之transition过渡 09.「布局技巧」图片未加载前自动撑开元素高度→

    最近更新
    01
    drag
    12-22
    02
    入场/出场05
    10-16
    03
    入场/出场04
    10-16
    更多文章>
    icon组件不能用
    时间左侧 © 2021-2021 时间右侧
    冀公网安备 13108202000744号
    • 跟随系统
    • 浅色模式
    • 深色模式
    • 阅读模式
    欢迎来到我的家
    Back