简体   繁体   English

AngularJS动画卡翻盖

[英]AngularJS animation card flip

I am trying to use the new AngularJS way of doing animations between page transitions and would like to incorporate a card flip (like http://jsfiddle.net/nicooprat/GDdtS/ ) 我试图使用新的AngularJS方式在页面转换之间进行动画制作,并希望合并卡片翻转(如http://jsfiddle.net/nicooprat/GDdtS/

body {
 background: #ccc;   
}
.flip {
-webkit-perspective: 800;
width: 400px;
height: 200px;
position: relative;
margin: 50px auto;
}
.flip .card.flipped {
-webkit-transform: rotatex(-180deg);
}
.flip .card {
width: 100%;
height: 100%;
-webkit-transform-style: preserve-3d;
-webkit-transition: 0.5s;
}
.flip .card .face {
 width: 100%;
 height: 100%;
 position: absolute;
 -webkit-backface-visibility: hidden ;
 z-index: 2;
 font-family: Georgia;
 font-size: 3em;
 text-align: center;
 line-height: 200px;
}
.flip .card .front {
 position: absolute;
 z-index: 1;
 background: black;
 color: white;
 cursor: pointer;
}
.flip .card .back {
 -webkit-transform: rotatex(-180deg);
  background: blue;
  background: white;
  color: black;
  cursor: pointer;
}

I am just a bit unsure how to update that code to make it work with AngularJS for a page transition. 我只是不确定如何更新该代码以使其与AngularJS一起用于页面转换。

Any thoughts? 有什么想法吗?

I realize this was a long time ago, but I was just doing this, and it took zero javascript. 我意识到这是很久以前的事了,但我只是这样做,并且它花了零javascript。 The key is ng-class. 关键是ng-class。 Here is a JSFIDDLE . 这是一个JSFIDDLE

The key is this line 关键是这条线

<div class="card" ng-class="{'flipped':isFlipped}" ng-click="isFlipped=!isFlipped"> 

It will assign the class 'flipped' to the card when $scope.isFlipped is true. $ scope.isFlipped为true时,它会将类“翻转”分配给卡片。 Here is a little NFL flash cards game I put together for fun. 这是一个非常有趣的NFL闪存卡游戏。 Check out the source code (which isn't super pretty), it should be helpful if you are doing something like this. 查看源代码(这不是非常漂亮),如果您正在执行此类操作,它应该会有所帮助。

NFL Flash Cards NFL闪存卡

Here is an alternate solution where it's more clear from the html what's happening. 是一个替代解决方案,从html中可以更清楚地知道发生了什么。 Specifically, the flip mechanism is in angularjs rather than buried in css magic. 具体来说,翻转机制是有角度的,而不是埋藏在css魔法中。 Perhaps easier to follow for anyone who's not a css expert: 对于不是css专家的人来说,也许更容易理解:

<div class="card" ng-click="isFlipped=!isFlipped">
    <div class="face front" ng-class="{'flipped':isFlipped}">
        Front
    </div> 
    <div class="face back" ng-class="{'flipped':!isFlipped}">
        Back
    </div> 
</div>

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

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