加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

结构-行为-样式-angularJs ngAnimate(Js实现)

发布时间:2020-12-17 10:13:32 所属栏目:安全 来源:网络整理
导读:声明 页面 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-contro
  • 声明
  • 页面
  • 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
                  },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三个方法;


五、官方链接

Angularjs-ngAnimate官方Api

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读