简体   繁体   English

角度动画:点击

[英]Angular animations: on click

I have a problem animating some elements in my Angular application. 我在Angular应用程序中为一些元素设置动画有问题。 There is a grid composed of cells (generated with a ng-repeat). 有一个由细胞组成的网格(用ng-repeat生成)。 What I want to do is create a simple animation: on click, the cell should disappear (fadeOut effect for instance) and reappear after a while. 我想要做的是创建一个简单的动画:单击时,单元格应该消失(例如fadeOut效果)并在一段时间后重新出现。

I've managed to do a fadeOut effect following this tutorial 我已经设法在本教程之后做了一个fadeOut效果

Here is the code that manages the cells: 以下是管理单元格的代码:

      <div class="col col-20 cell" style="background-image:url('img/gray.png')">
          <img class="cell-img" ng-src="{{cells[$index].getSrc()}}" width="100%" ng-click="click(cells[$index])" cell-click/>
       </div>
      <div class="col col-20 cell" style="background-image:url('img/gray.png')">
          <img class="cell-img" ng-src="{{cells[$index + 1].getSrc()}}" width="100%" ng-click="click(cells[$index + 1])" cell-click/>
      </div>
      <div class="col col-20 cell" style="background-image:url('img/gray.png')">
          <img class="cell-img" ng-src="{{cells[$index + 2].getSrc()}}" width="100%" ng-click="click(cells[$index + 2])" cell-click/>
      </div>
      <div class="col col-20 cell" style="background-image:url('img/gray.png')">
          <img class="cell-img" ng-src="{{cells[$index + 3].getSrc()}}" width="100%" ng-click="click(cells[$index + 3])" cell-click/>
      </div>
      <div class="col col-20 cell" style="background-image:url('img/gray.png')">
          <img class="cell-img" ng-src="{{cells[$index + 4].getSrc()}}" width="100%" ng-click="click(cells[$index + 4])" cell-click/>
      </div>
    </div>
app.controller("Control", function($scope, $interval, ...){
  $scope.click = function(cell){
    if($scope.gameStarted){
      if(cell.isActive){
        if(colorOk){
          // ...
        }
        else{
          // ...
        }
      }
    }
  }
}

You can use $timeout to make the cell reappear after a certain time after you hide it. 您可以使用$ timeout使单元格在隐藏后的某个时间后重新出现。

Something like: 就像是:

$timeout(function () {
    //code to make the cell appear/show the cell (maybe by removing ng-hide class)
  }, 1000);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM