[AnuglarJS] TweenMax with ngAnimate

Also read: http://www.cnblogs.com/Answer1215/p/3941966.html

Using ngAnimate:

//!annotate="YourApp" Your AngularJS Module|Replace this or ngModule with the module that you used to define your application.
var ngModule = angular.module(‘YourApp‘, [‘ngAnimate‘]);
ngModule.animation(‘.my-crazy-animation‘, function() {
  return {
    enter: function(element, done) {
      //run the animation here and call done when the animation is complete
      return function(cancelled) {
        //this (optional) function will be called when the animation
        //completes or when the animation is cancelled (the cancelled
        //flag will be set to true if cancelled).
      };
    },
    leave: function(element, done) { },
    move: function(element, done) { },

    //animation that can be triggered before the class is added
    beforeAddClass: function(element, className, done) { },

    //animation that can be triggered after the class is added
    addClass: function(element, className, done) { },

    //animation that can be triggered before the class is removed
    beforeRemoveClass: function(element, className, done) { },

    //animation that can be triggered after the class is removed
    removeClass: function(element, className, done) { }
  };
});

Example:

js:

angular.module(‘categories‘, [
    ‘eggly.models.categories‘,
    ‘ngAnimate‘
])

    .config(function ($stateProvider) {
        $stateProvider
            .state(‘eggly.categories‘, {
                url: ‘/‘,
                views: {
                    ‘[email protected]‘: {
                        controller: ‘CategoriesController‘,
                        templateUrl: ‘app/categories/categories.tmpl.html‘
                    },
                    ‘[email protected]‘: {
                        controller: ‘BookmarksController‘,
                        templateUrl: ‘app/categories/bookmarks/bookmarks.tmpl.html‘
                    }
                }
            });
    })

    .controller(‘CategoriesController‘, function ($scope) {

    })

    .directive(‘menuItem‘, function(){
        var controller = function($scope){
            $scope.mouse_over = false;
        };

        return {
            scope: true,
            controller: controller
        }
    })

    .animation(‘.menu-animation‘, function () {
        return {
            beforeAddClass: function (element, className, done) {
                if (className == ‘highlight‘) {
                    TweenLite.to(element, 0.2, {
                        width: ‘223‘,
                        borderLeft: ‘10px solid #89CD25‘,
                        onComplete: done
                    });
                    TweenLite.to(element.find(‘a‘), 0.2, {
                        color: "#89CD25"
                    });
                }
                else {
                    done();
                }
            },

            beforeRemoveClass: function (element, className, done) {
                if (className == ‘highlight‘) {
                    TweenLite.to(element, 0.4, {
                        width: ‘180‘,
                        borderLeft: ‘5px solid #333‘,
                        onComplete: done
                    });
                    TweenLite.to(element.find(‘a‘), 0.4, {
                        color: "#5bc0de"
                    });
                }
                else {
                    done();
                }
            }
        };
    });

HTML:

<a ng-click="setCurrentCategory(null)"><img class="logo" src="assets/img/eggly-logo.png"></a>
<ul class="nav nav-sidebar">
    <li menu-item ng-repeat="category in categories"
        class="menu-animation"
        ng-class="{‘highlight‘:mouse_over}"
        ng-mouseenter="mouse_over = true"
        ng-mouseleave="mouse_over = false"
        ng-class="{‘active‘:isCurrentCategory(category)}">
        <a  ng-click="setCurrentCategory(category)">
            {{category.name}}
        </a>
    </li>
</ul>

时间: 2024-12-17 00:06:59

[AnuglarJS] TweenMax with ngAnimate的相关文章

一款基于TweenMax跟随鼠标单击移动的div

今天给大家分享一款基于TweenMax跟随鼠标单击移动的div.在这款实例中你可以单击任意位置,div会移动到你单击的位置.效果图如下: 在线预览   源码下载 实现的代码. html代码: <html ng-app="app" ng-click="moveblock($event)"> <body> <block class="block">Where Do You Want Me?<br />C

ngRoute+ngAnimate与JQM中的页面跳转的区别

1.ngRoute+ngAnimate与jQM中的页面跳转有何异同? 相同点: (1)完整的HTML只需要一个 (2)使用异步AJAX请求获取下一个页面 (3)可以实现转场动画 不同点: (1)ngRoute需要配置路由字典:jQM没有,更加灵活 (2)ngRoute访问路由地址的格式——特殊格式的hash http://xxx/index.html#/main jQM访问页面地址——普通的URL http://xxx/tpl/main.html (3)ngRoute访问的路由页面可以使用F5刷

TweenMax学习整理--特有属性

TweenMax学习整理--特有属性 构造函数:TweenMax(target:Object, duration:Number, vars:Object) target:Object -- 需要缓动的对象 duration:Number -- 缓动持续时间 vars:Object -- 其它参数(特有属性29个,插件17个,公共属性10个,公共方法20个) TweenMax提供的方法大多都会返回一个TweenMax Object实例 [特有属性(29个)] 这29个参数可以直接传入第三个obje

tweenMax学习笔记

tweenMax是一款缓动插件,能实现很多牛逼的效果,在网上看了些demo,确实很吊,虽说很多用CSS3也能做出来,但是技多不压身,学之. 网上的demo还是很多的,但是资料不多,唯一能够让我有思绪的就是tweenMax的官网(http://greensock.com/tweenmax) 讲到这个Greensock,我还特意去了下它的gihub(https://github.com/greensock/GreenSock-JS),发现不止是tweenMax,还有一些诸如tweenLite这样的插

Angular 学习笔记——ng-animate

<!DOCTYPE HTML> <html ng-app="myApp"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>无标题文档</title> <script src="angular.min.js"></scrip

[CSS3 Animation] TweenMax.staggerTo()

<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8"> <title>Hello Greensock!</title> <link href='http://fonts.googleapis.com/css?family=Asap:400,700' rel='stylesheet' type='text/css'>

AngularJS学习--- 动画操作 (Applying Animations) ngAnimate step 12

1.切换目录 git checkout step-12 npm start 2.效果图 这里在点击右边的缩略图时,会有一个很明显的从下向上的动画过程. 3.代码实现: step11和step12之间的代码差异:https://github.com/angular/angular-phonecat/compare/step-11...step-12 Dependencies(依赖的js库): bower.json { "name": "angular-seed", &

TweenMax动画库学习(三)

目录: TweenMax动画库学习(一)            TweenMax动画库学习(二)            TweenMax动画库学习(三)            TweenMax动画库学习(四)            TweenMax动画库学习(五)                  尽请期待......

TweenMax动画库学习(二)

目录: TweenMax动画库学习(一)            TweenMax动画库学习(二)           更新中,尽请期待......