Use CSS3 to achieve image flip effect

不言
Release: 2018-06-14 16:35:36
Original
5094 people have browsed it

This article mainly introduces the method of creating flip effect with CSS3. CSS3 creates 3D card flip effect, which is suitable for poker flip and other games. It has certain reference value. Interested friends can refer to it

The flip effect produced by CSS3 is that when the mouse is moved over the element, it feels like you can see the information behind the element. If you make Lianliankan, poker-type games that test your memory, or even write some words to your girlfriend, you can try it after putting them in the photo album made using this example, ha~

Rendering:

Some new css3 properties used in the example:

a. -webkit-perspective: 800px;

Perspective (perspective, perspective): Attribute defines the distance of the 3D element from the view, in pixels. This property allows you to change the 3D element's view of the 3D element. Determines whether what you see is a 2D transform or a 3D transform.

b, -webkit-transform-style: preserve-3d;

The transform-style attribute specifies how to render nested elements in 3D space. The default is flat, we use 3D effect, and then select 3D.

c, -webkit-backface-visibility: hidden; Whether to display the selected element after it is rotated to the back.

d、-webkit-transform: rotateY(0); The element rotates around the Y axis.

The above attributes will give you a perceptual understanding first. After reading the examples, you can then taste these attributes carefully, or use Baidu or Google Shenma.

Example:

Html:

is quite simple:

ul is a set of pictures, and there is a in each li (because we I hope you can jump by clicking on the picture), a contains two p's, one is when it is displayed normally (that is, the picture is displayed), and the other is when the picture is rotated (that is, the introduction).

CSS:

 

    
Copy after login

Okay, in the above CSS you can find the CSS properties mentioned earlier in the article.

1. The most important thing is to understand rotateY, which rotates around the y-axis. Remember that I also used similar attributes transform: rotate(2520deg); in the exquisite case of HTML5 CSS3: realizing personalized slideshows in VCD packaging boxes. It's a 2D rotation.

rotateY literally rotates around the y-axis. Someone must ask where the y-axis is:

The default center point of the rotated element is the rotation center (you can pass transform-origin modification), the x and y axes are on the graph, and the z-axis is the arrow going out from the center (the arrow shooting towards your head from the screen).

In our example, the default image rotateY=0; the mouse pointer is rotateY=-180, a negative number means counterclockwise rotation around the y-axis, a positive number means clockwise rotation; the same applies to the other two axes;

The core of our example is that when the mouse points to: picture (p:first-child), it rotates 180 degrees counterclockwise around the y-axis from 0 degrees to -180 degrees; introduction (p:last-child) starts from 180 Rotate 180 degrees counterclockwise around the y-axis to reach 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.

Perspective, there is a trick for setting the stage (the parent element of the animation).

Transform-style’s 3D changes are of course 3D, there’s nothing much to say.

There are many more attributes related to the 3D effect of css3. If I have the opportunity, I will deliberately use unused ones in future examples~

The above is the entire content of this article. I hope it will be helpful to everyone's learning. Helpful, please pay attention to the PHP Chinese website for more related content!

Related recommendations:

How to use css to stretch and fill the background image to avoid repeated display

How to implement a canvas circular countdown Component

The above is the detailed content of Use CSS3 to achieve image 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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!