问题:动画在角种子项目中不起作用。我做了什么:
- 我从 github 获取了 angular-seed。
- 在种子项目中有两个视图,view1.html 和 view2.html 通过路由与它们相应的控制器很好地连接。
- 我用我最简单的 CSS 转换动画替换了 view1。(在另一个项目中工作正常)
- 在 View1 的脚本中,我将 'ngAnimate' 注入到模块中,如下所示: var animation3App = angular.module('animation3', ['ngAnimate']);
- 我将 "angular-animate": "1.2.x" 添加到 bower.json 并运行 bower install。我确认 angular-animate 已添加/安装到 bower_components 目录。
- 在 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>