【问题标题】:Can't get ngAnimate to work in new angular-seed project无法让 ngAnimate 在新的 angular-seed 项目中工作
【发布时间】:2014-09-18 08:02:27
【问题描述】:

问题:动画在 angular-seed 项目中不起作用。 我做了什么:

  1. 我从 github 获取了 angular-seed。
  2. 在种子项目中有两个视图,view1.html 和 view2.html 通过路由与其对应的控制器很好地连接。
  3. 我将 view1 替换为我最简单的 CSS 转换动画。 (在另一个项目中运行良好)
  4. 在 View1 的脚本中,我将“ngAnimate”注入到模块中,如下所示: var animation3App = angular.module('animation3', ['ngAnimate']);
  5. 我将 "angular-animate": "1.2.x" 添加到 bower.json 并运行 bower install。我确认 angular-animate 已添加/安装到 bower_components 目录。
  6. 在 index.html 中,我在 angular-route 和 app.js 之间添加了这一行,如下所示: ...src="bower_components/angular-animate/angular-animate.js"...

动画: 两个在彼此之上,单击一个应将其不透明度设置为 0,其他(即在下方为 1)从而将图像从一个更改为另一个,花费 1 秒的时间来更改不透明度,给出一个“合并”的效果。

当导航到 index.html 路由给我 view1.html 时,这就是 angular-seed 的路由方式,我没有碰它。如果不在 angular-seed 项目中效果很好的动画不起作用。图像被交换,但没有动画效果。

我在浏览器的 F12 工具中没有收到任何警告或错误。 有没有办法用batarang调试这个?

为简单起见,包含脚本的整个 view1.html:

<!DOCTYPE html>
<html ng-app="animation3">
<head lang="en">
    <link href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet">
</head>
<body ng-controller="animation3Ctrl">

<style>
    #image-container {
        position: relative;
        width: 200px;
        height: 200px;
    }
    .image-back{
        position: absolute;
        top: 25px;
        left: 25px;
        width: 150px;
        height: 150px;
        border: 1px lightcoral solid;
    }
    .image-front{
        position: absolute;
        top: 0px;
        left: 0px;
        width: 200px;
        height: auto; /*height: 200px;*/
        border: 1px lightcoral solid;
    }

    .animate-show {
        opacity:1;
    }
    .animate-show.ng-hide-add.ng-hide-add-active,
    .animate-show.ng-hide-remove.ng-hide-remove-active {
        -webkit-transition:all 1.7s;
        transition:all 1.7s;
    }
    .animate-show.ng-hide {
        opacity:0;
    }
</style>

<pre>
    This is view1.
    Click on Image to see animation.
    This HTML works perfectly well on it's own, but NOT inside this angular-seed project.
</pre>

<div id="image-container">
    <img class="image-front animate-show"
         ng-src="./img/{{photo.imgFront}}"
         ng-click="flipPhoto()"
         ng-show="frontShown">
    <img class="image-back animate-show"
         ng-src="./img/{{photo.imgBack}}"
         ng-click="flipPhoto()"
         ng-hide="frontShown">
</div>

<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.0-rc.0/angular.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.0-rc.0/angular-animate.js"></script>
<script>
    var animation3App = angular.module('animation3', ['ngAnimate']);

    animation3App.controller('animation3Ctrl', ['$scope',
        function ($scope) {
            $scope.photo = {
                imgBack: 'proXoftLogo.png',
                imgFront: 'donaldBlack.jpg'
            }

            $scope.flipPhoto = function flipPhoto(){
                $scope.frontShown = !$scope.frontShown;
            }
        }]);
</script>

</body>
</html>

【问题讨论】:

    标签: angularjs ng-animate angular-seed


    【解决方案1】:

    我解决了! 动画的 CSS 中存在错误。 我在问题中描述的 6 个步骤都是正确的。 我的问题与角种子无关。

    解决方案: 我将 CSS 更改为: (究竟哪一部分是关键部分,因为我正在学习角度动画,所以我还不知道)

    .animate-show.ng-hide-add,
    .animate-show.ng-hide-remove {
        -webkit-transition:all 1.7s;
        transition:all 1.7s;
    }
    .animate-show.ng-hide-add.ng-hide-add-active,
    .animate-show.ng-hide-remove{
        opacity:0;
    }
    .animate-show.ng-hide-add,
    .animate-show.ng-hide-remove.ng-hide-remove-active {
        opacity:1;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-10-24
      • 2020-11-23
      • 1970-01-01
      • 2017-04-04
      • 2014-04-26
      • 2020-08-21
      • 1970-01-01
      相关资源
      最近更新 更多