zoukankan      html  css  js  c++  java
  • css3 翻牌动画

    最近做了一个特效,css是从网上找的,地址是这个:

      CSS3 animate flip下的纸牌翻转效果实例页面

    把其中核心的css代码扒出来如下:

     1 /* The properties in this rule are only necessary for the 'flip' transition.
     2  * We need specify the perspective to create a projection matrix. This will add
     3  * some depth as the element flips. The depth number represents the distance of
     4  * the viewer from the z-plane. According to the CSS3 spec, 1000 is a moderate
     5  * value.
     6  */
     7 .viewport-flip {
     8     -webkit-perspective: 1000;
     9     perspective: 1000;
    10     position: absolute;
    11 }
    12 .flip {
    13     -webkit-backface-visibility: hidden;
    14     -webkit-transform: translateX(0); /* Needed to work around an iOS 3.1 bug that causes listview thumbs to disappear when -webkit-visibility:hidden is used. */
    15     backface-visibility: hidden;/*backface-visibility 属性定义当元素不面向屏幕时是否可见*/
    16     transform: translateX(0);
    17 }
    18 .flip.out {
    19     -webkit-transform: rotateY(-90deg) scale(.9);
    20     -webkit-animation-name: flipouttoleft;
    21     -webkit-animation-duration: 175ms;
    22     transform: rotateY(-90deg) scale(.9);
    23     animation-name: flipouttoleft;
    24     animation-duration: 175ms;
    25 }
    26 .flip.in {
    27     -webkit-animation-name: flipintoright;
    28     -webkit-animation-duration: 225ms;
    29     animation-name: flipintoright;
    30     animation-duration: 225ms;
    31 }
    32 .flip.out.reverse {
    33     -webkit-transform: rotateY(90deg) scale(.9);
    34     -webkit-animation-name: flipouttoright;
    35     transform: rotateY(90deg) scale(.9);
    36     animation-name: flipouttoright;
    37 }
    38 .flip.in.reverse {
    39     -webkit-animation-name: flipintoleft;
    40     animation-name: flipintoleft;
    41 }
    42 @-webkit-keyframes flipouttoleft {
    43     from { -webkit-transform: rotateY(0); }
    44     to { -webkit-transform: rotateY(-90deg) scale(.9); }
    45 }
    46 @keyframes flipouttoleft {
    47     from { transform: rotateY(0); }
    48     to { transform: rotateY(-90deg) scale(.9); }
    49 }
    50 @-webkit-keyframes flipouttoright {
    51     from { -webkit-transform: rotateY(0) ; }
    52     to { -webkit-transform: rotateY(90deg) scale(.9); }
    53 }
    54 @keyframes flipouttoright {
    55     from { transform: rotateY(0); }
    56     to { transform: rotateY(90deg) scale(.9); }
    57 }
    58 @-webkit-keyframes flipintoleft {
    59     from { -webkit-transform: rotateY(-90deg) scale(.9); }
    60     to { -webkit-transform: rotateY(0); }
    61 }
    62 @keyframes flipintoleft {
    63     from { transform: rotateY(-90deg) scale(.9); }
    64     to { transform: rotateY(0); }
    65 }
    66 @-webkit-keyframes flipintoright {
    67     from { -webkit-transform: rotateY(90deg) scale(.9); }
    68     to { -webkit-transform: rotateY(0); }
    69 }
    70 @keyframes flipintoright {
    71     from { transform: rotateY(90deg) scale(.9); }
    72     to { transform: rotateY(0); }
    73 }

       做一下简单的分析:

      html结构应该如下:

    1 <div id="box" class="box viewport-flip" title="点击翻面">
    2                     <a href="/" class="list flip out"><img src="http://image.zhangxinxu.com/image/blog/201210/puke-k.png" alt="纸牌正面"></a>
    3                     <a href="/" class="list flip"><img src="http://image.zhangxinxu.com/image/blog/201210/puke-back.png" alt="纸牌背面"></a>
    4                 </div>

    其中viewport-flip是父容器,这里的绝对定位我没有看明白为什么,尝试着去掉,依旧可以正常运行,其中最关键的就是这个.flip.out .flip.in,在这两个类上定义了动画事件,以out为例子如下:

     -webkit-transform: rotateY(-90deg) scale(.9);
        -webkit-animation-name: flipouttoleft;
        -webkit-animation-duration: 175ms;
    

      其中规定动画为:

    flipouttoleft
    1 @-webkit-keyframes flipouttoleft {
    2     from { -webkit-transform: rotateY(0); }
    3     to { -webkit-transform: rotateY(-90deg) scale(.9); }/*以Y轴旋转90度,这个时候就看不见了相当于隐藏了*/
    4 }

    这样就会产生一个动画目前正在显示的元素以Y轴旋转逆时针(由rotateY(-90deg)的正负控制逆时针还是顺时针)90度,从开始from(旋转0度,即不旋转),到最终旋转到90,旋转过程中scale(.9)表示旋转过程中元素大小为正常大小的90%。

      同理,in则是把一个已经旋转90度的元素相反的方向转回0度,这样元素就显示了。

       以上是对大神的代码的解读,难免有不正确的,望谅解

  • 相关阅读:
    windows的端口映射
    windows的ics
    关于windows的右键菜单项 注册表删除
    dig的使用 openwrt
    linux环境变量相关
    Difference between 2>&-, 2>/dev/null, |&, &>/dev/null and >/dev/null 2>&1
    openwrt ipv6
    ros资料参考
    ipv6的相关参考资料
    supervisor
  • 原文地址:https://www.cnblogs.com/onedayof2010/p/6733817.html
Copyright © 2011-2022 走看看