美文网首页
Animate.css的详解

Animate.css的详解

作者: TheoLin | 来源:发表于2017-03-28 22:07 被阅读0次

说明

Animate.css是一款简单高效的css库,里面封装了若干种简单的常见动画,适合快速使用,同时也方便进行按需修改。

用法

  1. 导入文件
<head>
      <link rel="stylesheet" href="animate.min.css">
</head>
  1. 给指定元素加上指定的动画样式
<div class="animated bounce"></div>

这里有两个类,第一个是必须类,每一个应用animate.css效果的元素都必须添加这个类名。第二个是不同效果的类,选择你想要的效果的类名添加即可。

  1. 如果说想给某个元素动态添加动画样式,可以通过jquery来实现:
$('#element').addClass('animated bounce');
  1. 当动画效果执行完成后还可以通过以下代码添加事件
$('#element').one('webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend', function);

注意

当效果执行完,元素还在文档流中占据着空间(即使你已经看不到元素),所以如果你想让元素真正消失,要在执行完动画时把元素隐藏起来,如:

$('#element').one('webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend', function(){
  $(this).hide();
});

不然有可能会产生一些你不希望出现的bug。

原理

animated类的代码如下:

.animated {
    -webkit-animation-duration: 1s;
    animation-duration: 1s;
    -webkit-animation-fill-mode: both;
    animation-fill-mode: both
}

bounce类的代码如下:

@-webkit-keyframes bounce {
    0%,
    100%,
    20%,
    53%,
    80% {
        -webkit-transition-timing-function: cubic-bezier(0.215, .61, .355, 1);
        transition-timing-function: cubic-bezier(0.215, .61, .355, 1);
        -webkit-transform: translate3d(0, 0, 0);
        transform: translate3d(0, 0, 0)
    }
    40%,
    43% {
        -webkit-transition-timing-function: cubic-bezier(0.755, .050, .855, .060);
        transition-timing-function: cubic-bezier(0.755, .050, .855, .060);
        -webkit-transform: translate3d(0, -30px, 0);
        transform: translate3d(0, -30px, 0)
    }
    70% {
        -webkit-transition-timing-function: cubic-bezier(0.755, .050, .855, .060);
        transition-timing-function: cubic-bezier(0.755, .050, .855, .060);
        -webkit-transform: translate3d(0, -15px, 0);
        transform: translate3d(0, -15px, 0)
    }
    90% {
        -webkit-transform: translate3d(0, -4px, 0);
        transform: translate3d(0, -4px, 0)
    }
}

@keyframes bounce {
    0%,
    100%,
    20%,
    53%,
    80% {
        -webkit-transition-timing-function: cubic-bezier(0.215, .61, .355, 1);
        transition-timing-function: cubic-bezier(0.215, .61, .355, 1);
        -webkit-transform: translate3d(0, 0, 0);
        -ms-transform: translate3d(0, 0, 0);
        transform: translate3d(0, 0, 0)
    }
    40%,
    43% {
        -webkit-transition-timing-function: cubic-bezier(0.755, .050, .855, .060);
        transition-timing-function: cubic-bezier(0.755, .050, .855, .060);
        -webkit-transform: translate3d(0, -30px, 0);
        -ms-transform: translate3d(0, -30px, 0);
        transform: translate3d(0, -30px, 0)
    }
    70% {
        -webkit-transition-timing-function: cubic-bezier(0.755, .050, .855, .060);
        transition-timing-function: cubic-bezier(0.755, .050, .855, .060);
        -webkit-transform: translate3d(0, -15px, 0);
        -ms-transform: translate3d(0, -15px, 0);
        transform: translate3d(0, -15px, 0)
    }
    90% {
        -webkit-transform: translate3d(0, -4px, 0);
        -ms-transform: translate3d(0, -4px, 0);
        transform: translate3d(0, -4px, 0)
    }
}

.bounce {
    -webkit-animation-name: bounce;
    animation-name: bounce;
    -webkit-transform-origin: center bottom;
    -ms-transform-origin: center bottom;
    transform-origin: center bottom
}

由此我们很清楚地知道animate.css就是利用css3 animation属性实现这些动画效果,从.animated中我们得知动画效果限制在1s中,这可能不是我们所想要的,所以我们可以对应用的元素进行一些修改,如:

element {
    animate-duration: 2s;    //动画持续时间
    animate-delay: 1s;    //动画延迟时间
    animate-iteration-count: 2;    //动画执行次数
}

相关文章

  • Animate.css的详解

    说明 Animate.css是一款简单高效的css库,里面封装了若干种简单的常见动画,适合快速使用,同时也方便进行...

  • 【Animate.css】CSS动画库

    本节目录 Animate.css简介 Animate.css基础用法 Animate.css配合JS的用法和讲解 ...

  • animate.css的使用方法

    animate.css介绍 animate.css是一个跨浏览器的css3动画库 animate.css基础使用 ...

  • VUE之动画特效

    1. 在vue使用animate.css库 安装:npm install animate.css --save引用...

  • CSS3的颜色渐变效果

    在 animate.css寻找自己想要的动态效果,看到标题Animate.css和按钮Animate it的颜色在...

  • 基于animate和fullpage制作动画demo的总结

    animate.css就是一个动画库,使用时注意点: 用法: Animate.css 当与jQuery...

  • vue day03

    1.transition结合animate.css实现过渡 步骤:1.引入animate.css文件2.在想要进行...

  • HTML常用框架

    框架一 :: Animate.css Animate.css是一个css动画样式库,可以减少我们的开发时间.它预设...

  • WOW.js – 让页面滚动更有趣

    前面提到了animate.css,在这里推荐一个能与animate.css完美结合的控件——wow.js WOW....

  • JavaScript---动画框架

    animate.css animate.css是一个来自国外的CSS3动画库,它预设了抖动(shake)、闪烁(f...

网友评论

      本文标题:Animate.css的详解

      本文链接:https://www.haomeiwen.com/subject/xkjcottx.html