zoukankan      html  css  js  c++  java
  • 结构-行为-样式-angularJs ngAnimate(Js实现)

    • 声明
    • 页面
    • Js
    • 注意事项
    • 官方链接

    一、声明

    注意animate的版本要与Angular的一致。

    <script src="jquery.1.9.1.min.js"></script>
    <script src="angular.js"></script>
    <script src="angular-animate.js"></script>

    二、页面

    <body ng-app="myApp" ng-controller="myCtrl">
     <div class="container">
        <h3>Animation-js</h3>
         <form class="form-search">
                <div class="input-append">
                  <input type="text" ng-model="search"
                         placeholder="Search user"
                         class="form-control" >
                </div>
                <ul class="example-animate-container">
                  <li class="animate-repeat"
                      ng-repeat="user in users | filter:search">
                    <a href="#"> {{user}} </a>
                  </li> 
               </ul>
            </form>
     </div>
    </body>

    三、Js

    var app =  angular.module('myApp', ['ngAnimate']); 
        app.controller('myCtrl',['$scope',function($scope){
            $scope.users = ['Fabio', 'Leonardo', 'Thomas', 'Gabriele', 'Fabrizio', 'John', 'Luis', 'Kate', 'Max'];
        }]);
        app.animation('.animate-repeat',function(){
            return {
                enter:function(element,done){
                    $(element).css({opacity:0});
                     jQuery(element).animate({
                            opacity: 1,
                            height:40
                            },300, done);
                          return function(isCancelled) {
                            if(isCancelled) {
                              jQuery(element).stop();
                            }
                          }
                },
                leave:function(element,done){
                    jQuery(element).animate({
                        opacity:0,
                        height:0
                      },300, done);
                      return function(isCancelled) {
                        if(isCancelled) {
                          jQuery(element).stop();
                        }
                      }
                },
                move:function(element,done){
                    //do not used
                }
            };
        });

    四、注意事项

    1、Angular的版本与Angular-animate的版本要一致,不然会报错;
    2、一个App内不能声名相同名字的Controller;
    3、上面例子只是ng-repeat的版本,其实还有其他版本;
    4、ng-repeat只用到了Animate声明Js版本中的enter,leave和move三个方法;
    5、有时候只控制高度就可以达到效果;


    五、官方链接

    Angularjs-ngAnimate官方Api

    Code is read far more than it's written
  • 相关阅读:
    Redis持久化
    《Hadoop权威指南·大数据的存储与分析》阅读笔记(未读完)
    《redis设计与实现》第一版 阅读笔记(未看完)
    LSMTree -> SStable 初体验
    Goland实现Set操作
    使用Goland操作Redis详解
    使用Python操作Redis详解
    学习笔记
    docker技术入门与实战 第三版
    Shell(笔记)
  • 原文地址:https://www.cnblogs.com/ChickenTang/p/5655393.html
Copyright © 2011-2022 走看看