[英]Angular.js 1.4.2 CSS Animations not working for ng-show
我正在嘗試在按鈕上添加CSS動畫,因此數據不會淡入或淡出。 但是當前單擊按鈕只是立即將類更改為ng-hide,或將其更改為ng-hide,因此動畫永遠不會被調用。 我正在嘗試根據Angular.js網站上給出的示例進行工作: https ://docs.angularjs.org/api/ng/directive/ngShow
網站上提供的工作代碼編碼器位於此處: http ://plnkr.co/edit/2ZJ9pdUq1tXLbDLuShEV?p=preview
我的代碼(出於某種原因無法進行動畫處理)位於 : http : //plnkr.co/edit/vnvVUciM5qMVyqzv2nL0?p=preview
HTML:
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap-theme.min.css">
<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<script src="http://code.angularjs.org/1.4.2/angular.js"></script>
<script src="http://code.angularjs.org/1.4.2/angular-animate.min.js"></script>
<script src="script.js"></script>
</head>
<body ng-app="assignment" ng-controller="AssignmentController as assignment">
<button type="button" ng-click="current_question_id = 0">0</button>
<button type="button" ng-click="current_question_id = 1">1</button>
<div class="panel-body" id="form_content">
<div ng-repeat="question in questions" ng-show="question.id == current_question_id" class="question-container">
<div class="position-center">
<div class="form-horizontal">
<div class="form-group">
<label for="question_question_{{ question.id }}" class="col-lg-2 col-sm-2 control-label">Question</label>
<div class="col-lg-10">
<input type="text" id="question_question_{{ question.id }}" name="questions[][question]" placeholder="Question" class="form-control" ng-value="question.question">
<p class="help-block">{{ question.type }}</p>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
CSS:
.question-container {
line-height: 20px;
opacity: 1;
padding: 10px;
}
.question-container.ng-hide-add.ng-hide-add-active,
.question-container:not(.ng-hide) {
-o-transition: all linear 0.5s;
-moz-transition: all linear 0.5s;
-webkit-transition: all linear 0.5s;
transition: all linear 0.5s;
}
.question-container.ng-hide {
line-height: 0;
opacity: 0;
padding: 0 10px;
}
JS:
(function(){
var app = angular.module('assignment', []);
app.controller('AssignmentController', function($scope, $http){
$scope.questions = [{id: 0, question: "What is the capital of Greenland?", type: "Short Answer"},
{id: 1, question: "Wtf is going on?", type: "Long Answer"}];
});
})();
似乎在我的代碼中,由於某種原因,該元素從未獲得ng-hide-add或ng-hide-remove類。 有任何想法嗎? 謝謝!
您需要將ngAnimate注入應用程序的模塊中:
(function(){
var app = angular.module('assignment', ['ngAnimate']);
app.controller('AssignmentController', function($scope, $http){
$scope.questions = [{id: 0, question: "What is the capital of Greenland?", type: "Short Answer"},
{id: 1, question: "Wtf is going on?", type: "Long Answer"}];
});
})();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.