如何使用AngularJS动画实现翻转效果? [英] How to implement a flip over effect using AngularJS animations?
问题描述
使用AngularJS动画实现翻转效果的最佳方法是什么?
What would be the best way to achieve a flip over effect using AngularJS animations?
我希望点击时发生翻转效果.每次单击时,它都应翻转到另一侧.
I would like the flip over effect to occur on click. Every time it's clicked, it should flip over to the other side.
理想情况下,我想我正在寻找一种使用Angular动画的指令实现.
Ideally, I guess, I'm looking for a directive implementation that uses Angular animations.
推荐答案
PLNKR -这是提供3d翻转功能的可配置角度指令的种子.我看不到为什么要使用ngAnimate
的任何好原因.
PLNKR - here is a seed of a configurable angular directive that provides 3d flipping functionality. I do not see any good reason why to use ngAnimate
for it.
<flip flip-width="200px" flip-height="100px">
<flip-panel>
content-front
</flip-panel>
<flip-panel>
content-back
</flip-panel>
</flip>
评论
- 它可以完全独立地附加css样式.
- 在适当的通用
directive
中,所有名称都应可配置. -
flip-width
和flip-height
设置flip
以及两个flip-panels
的样式. - 如果同时设置了
front
和back
,则指令进行一些基本检查. - 第一个
flip-panel
是front
,第二个是back
. -
由于使用了(您是正确的Misha,不需要包含任何内容)flip-panel
的transclusion
内容,因此可能是任意html. - 它仅在
-webkit
中起作用. (更新使其可以在Firefox中运行,只需使用-webkit
复制所有片段,并且不带前缀-您不需要-moz
)
- It appends css-styles on its own, to be fully independent.
- In a proper, generic
directive
all names should be configurable. flip-width
andflip-height
sets style offlip
and bothflip-panels
.- Directive makes some basic check, if both
front
andback
are set. - First
flip-panel
isfront
and the second isback
. Due to usage of(you are right Misha no transclusion needed)transclusion
content of theflip-panel
may be arbitrary html.- It only works in
-webkit
. (update to make it work in Firefox, just duplicate all pieces with-webkit
with no prefix - you do not need-moz
)
更新
PLNKR -这是更新和扩展的版本.它显示了使指令可配置的含义.详细信息:
UPDATE
PLNKR - here is an updated and extended version. It shows what I meant by making the directive configurable. In more details:
- 通过
provider
引入了flipConfig
,可以在app.config
中进行设置:- 默认尺寸
- css类名称
- 过渡速度
- 如果翻转动作是通过单击面板触发的
- Introduced
flipConfig
viaprovider
, that allows to set inapp.config
:- default dimensions
- css class names
- speed of the transition
- if the flip action is triggered by a click on the panel
(顺便说一句:它只是一个种子,并且可以通过许多方式进行改进.例如:指定轴,指定变换的原点,指定面板的半径和边距,允许鼠标悬停,默认颜色,边距等)
(btw: it is just a seed and it may be improved in a lot of ways. E.g: specifying axis, specifying origin of the transform, specifying radius and margin of the panels, allowing flip on hover, defaults colors, margins and so on)
这篇关于如何使用AngularJS动画实现翻转效果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!