前端 animation 动画(用的到的都写了)直接用animate库最方便用法加粗了

<!--建议直接复制丢到vscode去看,很清楚-->

<!DOCTYPE html>

<html lang="en">

  <head>

    <meta charset="UTF-8" />

    <meta name="viewport" content="width=device-width, initial-scale=1.0" />

    <title>Document</title>

    <link

      rel="stylesheet"

      href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/4.0.0/animate.min.css"

    />

    <!-- 

            animation动画

        animation-name 设置动画的名字

        animation-duration 动画的持续时间

        animation-delay 动画的延迟时间

        animation-iteration-count 动画的重复次数,默认值是1,infinite无限次数

        animation-timing-function 动画的运动形式

        animation-fill-mode 规定动画播放之前或之后,其动画效果是否可观

          none 默认 在运动结束之后回到初始位置,在延迟的情况下,让0%在延迟后生效

          backwards 在延迟的情况下,让0%在延迟前生效

          forwards 在运动结束之后,停到结束位置

          both backwards和forwards同时生效

        animation-direction 属性定义是否应该轮流反向播放动画

          alternate 一次正向(0%-100%),一次反向(100%-0%)

          reverse 永远都是反向,从(100%-0%)

          normal 默认 永远都是正向,从(0%-100%)

        animate css库

        网址:https://animate.style/

         <link

    rel="stylesheet"

    href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/4.0.0/animate.min.css"

  /> 直接复制就行link到最前面

  然后去官网找怎么用,复制样式名字添加到class中就行(具体规则根据官网定 版本不同规则不同)

 

        注:

        0%就是form 100%就是to

        用动画可以用很多关键帧


 

    -->

    <style>

      .box1 {

        width: 300px;

        height: 300px;

        border: 1px solid black;

        margin: 30px auto;

      }

      .box2 {

        width: 100px;

        height: 100px;

        background-color: blue;

        /* animation-name: myBox;

        animation-duration: 4s; */

        animation: myBox 4s 1s infinite linear;

      }

      @keyframes myBox {

        form {

          transform: translate(0, 0);

        }

        to {

          transform: translate(200px, 0);

        }

      }

      .div1,

      .div2,

      .div3,

      .div4 {

        width: 100px;

        height: 100px;

        background-color: rosybrown;

        margin: 5px;

      }

      .div1 {

        animation: 2s 1s move;

      }

      .div2 {

        animation: 2s 1s move;

        animation-fill-mode: backwards;

      }

      .div3 {

        animation: 2s 1s move;

        animation-fill-mode: forwards;

      }

      .div4 {

        animation: 2s 1s move;

        animation-fill-mode: both;

      }

      @keyframes move {

        0% {

          transform: translate(0, 0);

          background-color: royalblue;

        }

        100% {

          transform: translate(500px, 0);

        }

      }

      .fangxiang01,

      .fangxiang02,

      .fangxiang03 {

        width: 100px;

        height: 100px;

        margin-top: 20px;

        background-color: salmon;

        animation: 1s fx infinite;

      }

      .fangxiang01 {

        animation-direction: alternate;

      }

      .fangxiang02 {

        animation-direction: normal;

      }

      .fangxiang03 {

        animation-direction: reverse;

      }

      @keyframes fx {

        0% {

          transform: translate(0, 0);

        }

        100% {

          transform: translate(200px, 0);

        }

      }

      .donghua {

        width: 100px;

        height: 50px;

        margin-top: 50px;

        background-color: salmon;

      }

    </style>

  </head>

  <body>

    <div class="box1">

      <div class="box2"></div>

    </div>

 

    <div class="div1"></div>

    <div class="div2"></div>

    <div class="div3"></div>

    <div class="div4"></div>

 

    <div class="fangxiang01"></div>

    <div class="fangxiang02"></div>

    <div class="fangxiang03"></div>

 

    <div class="donghua animate__animated animate__bounce"></div>

  </body>

</html>

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,这里给你提供一种使用自定义类名和animate.css动画给一张图片添加入场动画的示例。使用animate.css可以方便地实现CSS动画效果,具体可以根据需求自定义。 首先,需要在HTML文件中引入animate.css的CDN链接: ```html <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/4.1.1/animate.min.css" /> ``` 然后,HTML代码如下: ```html <div class="image-wrapper animate__animated"> <img src="image.jpg" alt="图片"> </div> ``` CSS代码如下: ```css .image-wrapper { position: relative; display: inline-block; } .image-wrapper.animate__animated { animation-duration: 1s; /* 设置动画持续时间 */ animation-delay: 0.5s; /* 设置动画延迟时间 */ animation-fill-mode: both; /* 设置动画结束后保持最后状态 */ animation-name: slideInLeft; /* 设置动画名称 */ } @keyframes slideInLeft { from { transform: translateX(-100%); } to { transform: translateX(0); } } .image-wrapper img { display: block; max-width: 100%; height: auto; } ``` 这段代码使用了animate.css中的slideInLeft动画效果,通过给`.image-wrapper`添加类名`.animate__animated`来触发动画效果。其中,`.image-wrapper.animate__animated`使用了CSS3动画属性animation,通过设置animation-duration、animation-delay、animation-fill-mode、animation-name属性来定义动画效果。同时,利用@keyframes定义了从左侧平移进入的动画效果。最后,`.image-wrapper img`设置了图片的基本样式,其中max-width: 100%可以确保图片的宽度不会超出其容器的宽度。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值