无法获得AngularJS动画以改变视图

时间:2014-07-05 22:19:16

标签: javascript angularjs angularjs-animation

我已经阅读过AngularJS文档,做了几个教程,包括scotch和moo。我可以让他们的示例代码运行。

但是,我似乎并不了解Angular应用CSS样式创建动画的触发器是什么。我理解角度1.2应该自动应用它们,但这似乎对我不起作用。

我的目标是将视图(以及控制器)的更改设置为动画。 我没有显示子视图或其他CSS的内容,但如果需要,我可以。

以下是代码:

这是JS

var triStartApp = angular.module('triStartApp', ['ngAnimate', 'ngRoute']);
// create the controller and inject Angular's $scope
// configure our routes
routeFunction = function($routeProvider) {

    $routeProvider.when('/', {
        templateUrl: 'html/home.html',
        controller: 'mainController'
    });

    // route for the about page
    $routeProvider.when('/about', {
        templateUrl: 'html/about.html',
        controller: 'aboutController'
    });    
};

triStartApp.config(routeFunction);

// create the controller and inject Angular's $scope
triStartApp.controller('mainController', function($scope) {
    // create a message to display in our view
    $scope.message = 'Everyone come and see how good I look!';
});

triStartApp.controller('aboutController', function($scope) {
    $scope.message = 'Look! I am an about page.';
});

这是CSS:

.view.ng-enter {
  animation:view_enter 1s;
}

@keyframes view_enter {
  0% { left:100%; }
  30% { left:80%; }
  100% { left:0; }
}

.view.ng-leave {
  animation:view_leave 1s;
}
@keyframes view_leave {
  0% { left:0; }
  30% { left:-50px; }
  100% { left:-100%; }
}

这是HTML:

<html lang="en" ng-app="triStartApp">
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <meta name="description" content="">
        <meta name="author" content="">
        <!-- <link rel="shortcut icon" href="../../assets/ico/favicon.ico"> -->

        <title>TriStart</title>

        <!-- Bootstrap core CSS -->
        <link href="/css/bootstrap.min.css" rel="stylesheet">

        <!-- Custom styles for "cover" template -->
        <link href="/css/cover.css" rel="stylesheet">
        <link href="/css/animations.css" rel="stylesheet">

        <!-- Custom styles for tristart  -->
        <link href="/css/tristart.css" rel="stylesheet">    

    </head>

    <body ng-controller="mainController">          

        <div class="site-wrapper">

            <div class="site-wrapper-inner">

                <div class="cover-container">

                    <div class="masthead clearfix">

                        <div class="inner">
                            <h2 class="masthead-brand">TriStart</h2>
                            <ul class="nav masthead-nav">
                                <li class="active"><a href="#">Home</a></li>
                                <li><a href="#about">About</a></li>
                            </ul>
                        </div>

                        <div class="row">
                            <div class="col-md-12">
                                <p class="tristart-lead">(triangle startup resources)</p>                       
                            </div>                        
                        </div>                        
                    </div>


                    <div id="main" >
                        {{ message }}  
                        <!-- angular templating -->
                        <!-- angular templating -->
                        <!-- this is where content will be injected -->
                        <div>
                            <div class="view" ng-view></div>
                        </div>

                    </div>

                </div>

            </div>

        </div>

        <!-- Bootstrap core JavaScript
        ================================================== -->
        <!-- Placed at the end of the document so the pages load faster -->
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
        <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.13/angular.min.js"></script>
        <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.13/angular-route.js"></script>
        <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.13/angular-animate.js"></script>
        <script src="/js/script.js"></script>             
        <script src="/js/lib/bootstrap.min.js"></script>
        <script src="/js/lib/docs.min.js"></script>
    </body>
</html>

1 个答案:

答案 0 :(得分:0)

如果您没有执行复杂的自定义动画,则可以考虑使用ng-fx