CSS3 achieves dynamic card flip effect

小云云
Release: 2017-12-26 09:55:14
Original
3459 people have browsed it

Imitating the special effects of Baidu Tieba’s 3D card flipping once animation, this article mainly shares a special effect that uses the new CSS3 feature transform to achieve 3D card flipping special effects. Friends in need can refer to it. Hope it helps everyone.

Today I will share a card flip effect made with CSS3. The effect is as shown in the picture below. If you apply this effect to the photo album, it will definitely be very dazzling. Haha, super cool.

CSS3 achieves dynamic card flip effect

1. HTML code:

Because it is implemented in CSS3, you can see that there is no JS code. ul is a set of pictures. Each li has an a (because we want to jump by clicking on the picture). a contains two p, one is for normal display (that is, the picture is displayed), and the other is for display after the picture is rotated. (i.e. introduction).


<!doctype html>
<html>
  <head>
    <meta charset="gb2312">
    <title>百度帖吧 CSS3 翻牌效果</title>
    <link rel="stylesheet" type="text/css" href="style/reset.css">
    <link rel="stylesheet" type="text/css" href="style/tieba.brand.css">
  </head>
  
  <body>
   <h1>百度帖吧 CSS3 翻牌效果</h1>
    <h2>powered by <a href="http://blog.wangjunfeng.com" target="_blank">射雕天龙的博客</a></h2>
    <p id="content">
     <ul>
       <li>
         <a href="http://blog.wangjunfeng.com" target="_blank">
           <p><img alt="" src="images/1.jpg"/></p>
            <p>
             <h3>漩涡鸣人</h3>
              <p>日本漫画家岸本齐史作品《火影忍者》中男主角。因为身上封印着邪恶的九尾妖狐,无父无母的他受尽了村人的冷眼与歧视,他下定决心要成为第六代火影,让所有人都认同他的存在。</p>
            </p>
          </a>
        </li>
        <li>
         <a href="http://blog.wangjunfeng.com" target="_blank">
           <p>
             <img alt="" src="images/2.jpg"/>
            </p>
            <p>
             <h3>日向雏田</h3>
              <p>日本漫画家岸本齐史作品《火影忍者》中的3号女主角。木叶忍者村的女忍者,木叶名门日向一族宗家族长的长女。喜欢漩涡鸣人,原本是个性格柔弱的女孩,但是在鸣人的影响下逐渐变得坚强,并逐渐成长为一名优秀的忍者。</p>
            </p>
          </a>
        </li>
        <li>
         <a href="http://blog.wangjunfeng.com" target="_blank">
           <p><img alt="" src="images/3.jpg"/></p>
            <p>
             <h3>蒙奇·D·路飞</h3>
              <p>蒙奇·D·路飞 是日本人气动漫 《海贼王》中的主人公。是日本人气动漫 《海贼王》中的主人公。草帽海贼团船长,梦想是找到传说中的宝藏 —— ONE PIECE,成为海贼王。</p>
            </p>
          </a>
        </li>
        <li>
         <a href="http://blog.wangjunfeng.com" target="_blank">
           <p>
             <img alt="" src="images/4.jpg"/>
            </p>
            <p>
             <h3>盒子先生</h3>
              <p>Danbo是一只用废纸盒DIY出来的可爱玩偶,圆圆的眼睛和三角形的嘴巴,时刻露出无辜的表情,让人看到就心软,Danbo是个纯真善良的小家伙,在它单纯的幻想世界里,总是透露出最纯真可爱的动人气息。</p>
            </p>
          </a>
        </li>
      </ul>
    </p>
  </body>
</html>
Copy after login

2. CSS3 code

I have made comments in some places, it should be easy to understand.


#content ul{
 width:960px;
 padding:60px 0;
 margin:0 auto;
}
#content ul li{
 width:225px;
 height:180px;
 margin-right:20px;
 float:left;
}
#content ul li:last-child{
 margin-right: 0;
}
#content ul li a{
 display:block;
 height:180px;
 /*
 设置元素被查看位置的视图:
 perspective 属性定义 3D 元素距视图的距离,以像素计。该属性允许您改变 3D 元素查看 3D 元素的视图。
 当为元素定义 perspective 属性时,其子元素会获得透视效果,而不是元素本身。
 */
 -webkit-perspective:500px; 
 -moz-perspective:500px;
 -ms-perspective:500px;
 perspective:500px;
 
 position: relative;
}
#content ul li a > p{
 top:0;
 left:0;
 width:100%;
 height:180px;
 color:#fff;
 
 /*
 指定嵌套元素如何在3D空间中呈现。
 */
 -webkit-transform-style: preserve-3d;
 -moz-transform-style: preserve-3d;
 -ms-transform-style: preserve-3d;
 
 /*
 隐藏被旋转的 p 元素的背面
 */
 -webkit-backface-visibility: hidden;
 -moz-backface-visibility: hidden;
 -ms-backface-visibility: hidden;
 
 -webkit-transition:0.8s ease-in-out ;
 -moz-transition:0.8s ease-in-out ;
 -ms-transition:0.8s ease-in-out ;
 
 position:absolute;
}
#content ul li a p:first-child{
 -webkit-transform: rotateY(0);
 -moz-transform: rotateY(0);
 -ms-transform: rotateY(0);
 z-index: 2;
}
#content ul li a:hover p:first-child{
 -webkit-transform: rotateY(-180deg);
 -moz-transform: rotateY(-180deg);
 -ms-transform: rotateY(-180deg);
}
#content ul li a p:last-child{
 -webkit-transform: rotateY(180deg);
 -moz-transform: rotateY(180deg);
 -ms-transform: rotateY(180deg);
 z-index: 1;
 background:url(&#39;../images/bg.jpg&#39;) no-repeat;
}
#content ul li a:hover p:last-child{
 -webkit-transform: rotateY(0);
 -moz-transform: rotateY(0);
 -ms-transform: rotateY(0);
 z-index: 1;
}
#content ul li a p h3{
 margin:0 auto 15px;
 padding:15px 0;
 width:200px;
 height:16px;
 line-height:16px;
 font-size: 14px;
 text-align: center;
 border-bottom:1px #fff dashed;
}
#content ul li a p p{
 padding:0 10px;
 font-size: 12px;
 text-indent: 2em;
 line-height:18px;
}
Copy after login

3. Implementation Principle

The default image rotateY=0; the mouse pointer is rotateY=-180, a negative number, that is Rotate counterclockwise around the y-axis. If it is a positive number, it is clockwise. The same applies to the other two axes. When the mouse points to: picture (p:first-child), rotate counterclockwise around the y-axis from 0 degrees by 180 degrees to -180 degrees. ;Introduction (p:last-child) rotates 180 degrees counterclockwise around the y-axis from 180 degrees to 0 degrees. Creates the effect of two counterclockwise rotations together. Some people may ask why the default introduction is not 0 degrees. Note here that the introduction is in a frontal state after being rotated 180 degrees counterclockwise, so when the image is covered, it is equivalent to a 180-degree clockwise rotation from the normal state, because when the mouse points Need to return to normalcy.

4. Source code download

http://xiazai.jb51.net/201605/yuanma/CSS3_BaiduTieba_Flop%28jb51.net%29.rar

5. Summary

CSS3 provides many new features such as transform. When we use these features, they may only be compatible with new browsers. For IE6, 7, and 8 The compatibility of such old antiques is not very good, but it is enough. For example, in the above example, in browsers such as IE6, 7, and 8, no special effects are displayed, only pictures are displayed, and they are not ugly. In other browsers, they are compatible with HTML5 and CSS3. In better browsers, you can see the special effects. It avoids using too much JS and achieves a cool display effect in new browsers.

Related recommendations:

Detailed explanation of Angularjs filter to implement dynamic search and sorting functions

Steps to implement the effect of creating dynamic switches in Css3

Several ways to create dynamic effects in HTML 5

The above is the detailed content of CSS3 achieves dynamic card flip effect. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template