animate库

2018-08-24  本文已影响151人  9979eb0cd854

Animate.css 一款强大的预设css3动画库

教程网址:http://www.jq22.com/yanshi819
下载和使用:http://www.mamicode.com/info-detail-2189430.html
下载地址:http://www.haorooms.com/uploads/example/Animatecss/

直接在页面顶部head标签通过link引入<link rel="stylesheet" type="text/css" href="css/animate.min.css"/>
image.png
image.png

用法

1、首先引入animate css文件

<head>
  <link rel="stylesheet" href="animate.min.css">
</head>

2、给指定的元素加上指定的动画样式名

<div class="animated bounceOutLeft"></div>

这里包括两个class名,第一个是基本的,必须添加的样式名,任何想实现的元素都得添加这个。第二个是指定的动画样式名。
3、如果说想给某个元素动态添加动画样式,可以通过jquery来实现:

$('#yourElement').addClass('animated bounceOutLeft');

4、当动画效果执行完成后还可以通过以下代码添加事件

$('#yourElement').one('webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend', doSomething);

你也可以通过 JavaScript 或 jQuery 给元素添加这些 class,比如:

$(function(){
    $('#jq22').addClass('animated bounce');
});

有些动画效果最后会让元素不可见,比如淡出、向左滑动等等,可能你又需要将 class 删除,比如:

$(function(){
    $('#jq22').addClass('animated bounce');
    setTimeout(function(){
        $('#jq22').removeClass('bounce');
    }, 1000);
});

animate.css 的默认设置也许有些时候并不是我们想要的,所以你可以重新设置,比如:

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

最简单的用法:

image.png
image.png

与JQ使用

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title>animate库的使用</title>
        <!--引入animate.css库文件-->
        <link rel="stylesheet" type="text/css" href="css/animate.min.css"/>
        <style>
            .box {
                width: 200px;
                height: 200px;
                background-color: purple;
                margin: 80px auto;
            }
        </style>
    </head>
    <body>
        <a href="">按钮</a>
        <!--给指定的元素加上指定的动画样式名-->
        <div class="box animated bounce"></div>
        
        <script src="js/jquery-1.8.3.min.js"></script>
        <script>
            $(function(){
                $('a').click(function(){
                    $('.box').addClass('animated bounce');
                })
            })
        </script>
    </body>
</html>

上一篇 下一篇

猜你喜欢

热点阅读