CSS3 for dynamic flop effects

Source: Internet
Author: User
Modeled after Baidu Bar 3D flop an animated effect, this article mainly share a new feature of the use of CSS3 transform, 3D to achieve the effect of the flop, the need for small partners can refer to the next. Hope to help everyone.

Today to share a CSS3 produced by the effect of the flop, as shown, the effect of the application to the album will certainly be very flashy. Oh, super cool AH.

First, the HTML code:

Because it is CSS3 implementation, so you can see there is no JS code. UL for a group of pictures, each Li has a (because we want to click on the image can jump), a contains two p, one is normal display (that is, display pictures), one is the picture rotated after the display (that is, introduction).


<!doctype html>

Second, CSS3 code

I have made some comments in the inside part of the place, 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;/* Sets the view where elements are viewed: The Perspective property defines the distance, in pixels, of the 3D element from the view. This property allows you to change the 3D element view of the 3D element. When you define a perspective property for an element, its child elements get a perspective instead of the element itself.  */-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; /* Specifies how nested elements are rendered in 3D space. */-webkit-transform-style:preserve-3d; -moz-transform-style:preserve-3d;  -ms-transform-style:preserve-3d; /* Hide the back of the rotated P element */-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 ('.. /images/bg.jpg ') 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; te Xt-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;}

Three, the realization principle

The default picture rotatey=0, the mouse points to rotatey=-180, negative, that is, counterclockwise around the y-axis rotation, positive, or clockwise; the other two axes in the same way; When the mouse is pointing: Picture (P:first-child), 0 degrees counterclockwise from the Y axis 180 degrees to reach-180 degrees Introduction (P:last-child) rotates 180 degrees counterclockwise from 180 degrees around the y axis to 0 degrees. Results in two counterclockwise rotations. Some people may ask why the introduction of the default is not 0 degrees, here Note that the introduction of counterclockwise rotation of 180 degrees after the positive state, so when the image is obscured, the equivalent of a clockwise rotation from the normal state of 180 degrees, because the mouse point needs to return to normal state.

Four, source code download

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

V. Summary

CSS3 provides a lot of new features, such as transform, when we use these features may only be compatible with the new browser, the IE6, 7, 8 such as the old age compatibility is not very good, but this is enough, such as the above example, in the IE6, 7, 8 these browsers do not display effects, Show only pictures, not ugly, in other browsers for HTML5 and CSS3 compatible browser, you can see the effects. Avoid the use of too many JS, but also to achieve in the modern browser display cool effect.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.