Home >Web Front-end >H5 Tutorial >Achieve card 3D flip effect

Achieve card 3D flip effect

php中世界最好的语言
php中世界最好的语言Original
2018-03-20 13:52:056890browse

This time I will bring you the precautions to achieve the 3D flipping effect of cards. What are the precautions? Here is a practical case, let’s take a look.

This article introduces the sample code for CSS to achieve the 3D flip effect of cards, and shares it with everyone. The details are as follows:

Effect:

Code :

html:

<p class="main">
  <p class="box b1"></p>
  <p class="box b2"></p>
</p>

css:

.main {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 300px;
  height: 300px;
  transform: translate(-50%,-50%);
  -webkit-perspective: 1500;
  -moz-perspective: 1500;
}
.box {
  position: absolute;
  top: 0;
  left: 0;
  width: 300px;
  height: 300px;
  transition: all 1s;
  backface-visibility: hidden;
  border-radius: 10px;
  cursor: pointer;
}
.b1{
  background:skyblue;
}
.b2 {
  background:tomato;
  transform: rotateY(-180deg);
}

javascript:

var b1 = document.querySelector(".b1");
var b2 = document.querySelector(".b2");
b1.onclick = function() {
  b1.style.transform = "rotateY(180deg)";
  b2.style.transform = "rotateY(0deg)";
}
b2.onclick = function() {
  b2.style.transform = "rotateY(-180deg)";
  b1.style.transform = "rotateY(0deg)";
}

-webkit-perspective: Perspective effect

backface-visibility: Hide the back side of the rotated p element

I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the PHP Chinese website!

Recommended reading:

h5 implements multiple image preview uploads and clickable drag controls

Front-end technology implements text texture overlay

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

Statement:
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