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.
Ideally, I guess, I'm looking for a directive implementation that uses Angular animations.
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>
directive
all names should be configurable.flip-width
and flip-height
sets style of flip
and both flip-panels
.front
and back
are set.flip-panel
is front
and the second is back
.transclusion
content of the flip-panel
may be arbitrary html.-webkit
. (update to make it work in Firefox, just duplicate all pieces with -webkit
with no prefix - you do not need -moz
)PLNKR - here is an updated and extended version. It shows what I meant by making the directive configurable. In more details:
flipConfig
via provider
, that allows to set in app.config
:
flip-show
attribute that specifies which side to show.flip-show
we can trigger the flip action from outside of the directive.(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)