CSS动画2----- 移动端盒子旋转显示文字

本文详细介绍了一个使用CSS实现的动画案例,包括文字透明度变化、盒子缩放旋转、背景颜色渐变及圆角变换等效果。通过关键帧动画,展示了如何在不同时间点设置元素的状态,实现了流畅且富有创意的视觉体验。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

学习链接:B站视频

演示

在这里插入图片描述

代码

<body>
    
  <main>
  </main>
    
</body>
    main {
      width: 100vw;
      height: 100vh;
      background-color: #34495e;
      transform: scale(0);  /* 设置缩放刚开始为0 */ 
      animation-name: scale, background, radius; /* 盒子添加动画名称 */
      animation-duration: 2s, 3s, 2s;  /* 设置每个动画的时间 */
      animation-fill-mode: forwards;  /* 设置动画状态在最后定格 */

      display: flex;
      align-items: center;
      justify-content: center;
    }
    main::after {   /* 设置文字伪元素 */
      content: '鸭鸭最帅';
      font-size: 2em;
      color: #ffffff;
      opacity: 0;
      animation-name: opacity;    /* 文字添加动画名称 */
      animation-duration: 2s;     /* 设置动画的时间 */
      animation-delay: 3s;        /* 设置动画延迟时间 */
      animation-fill-mode: forwards; /* 设置动画状态在最后定格 */
    }

    @keyframes opacity { /* 定义关键帧: 透明度 */
      to {
        opacity: .8;
      }
    }

    @keyframes scale {  /* 定义关键帧: 缩放,旋转 */
      25% {
        transform: scale(0.5);
      } 
      50% {
        transform: scale(1) rotate(360deg);
      }
      75% {
        transform: scale(0.5);
      }
      100% {
        transform: scale(1);
      }
    }

    @keyframes background { /* 定义关键帧:颜色 */
      25% {
        background-color: #2ecc71;
      } 
      50% {
        background-color: #f1c40f;
      }
      75% {
        background-color: #8e44ad;
      }
      100% {
        background-color: #e74c3c;
      }
    }

    @keyframes radius { /* 定义关键帧: 圆角 */
      25% {
        border-radius: 50%;
      } 
      50% {
        border-radius: 0;
      }
      75% {
        border-radius: 50%;
      }
      100% {
        border-radius: 0;
      }
    }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值