CSS& Javascript将rotateY转换为元素的后面

时间:2018-05-15 21:24:57

标签: javascript jquery css animation css-animations

这是我想做的事情:
1-zoom并将其旋转到中心(完成)
2张开卡(已完成)
3 - 查看卡的背面,然后再次转到打开的卡的正面。

有关如何操作的任何提示?我很困惑,香港专业教育学院尝试使用z-index和旋转变换,但没有运气。 到现在为止是否正确?你有什么建议,如何实现旋转到整个卡片的背面,然后到前面? 提前谢谢你

function pers(){
 document.getElementById("wrap").style.transform = "rotateX(0deg) rotate(0deg)";
 document.getElementById("wrap").style.width = "250px";
 document.getElementById("wrap").style.height = "500px";
}


function openCard() {
  
  var button = document.getElementById('button');
  
  if(button.innerHTML == 'Open Card') {
    button.innerHTML = 'Close Card';
  } else {
    button.innerHTML = 'Open Card';
  }
  
  var cards = document.querySelectorAll('.card');
  for(var i = 0; i < cards.length; i++) {
    cards[i].classList.toggle('open');
  }
    

}
body {
  margin: 0;
  background-color: grey;
  /*background: radial-gradient(circle at center, rgba(50,50,50,1) 0%,rgba(14,14,14,1) 35%) */
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100vh;
  perspective: 1000px;
  transform-style: preserve-3d;
}

img {
  max-width: 100%;
}

*, *:after, *:before {
  box-sizing: border-box;
}

h2 {
  font-family: "Dancing Script", serif;
  font-weight: normal;
  font-size: 45px;
  color: #009500;
  text-align: center;
}

.wrap {
  width: 125px;
  height: 250px;
  position: relative;
  transform: rotateX(40deg) rotate(15deg);
  transform-style: preserve-3d;
  box-shadow: 15px 10px 5px rgba(0, 0, 0, 0.3);
  transition: all 3s linear;

}

.card {
  height: 100%;
  width: 100%;
  background-color: #fff;
  border-radius: 2px;
  position: relative;
  border: 4px solid black;
  text-align: center;
 
}
.card--front {
   transform: rotateY(-20deg);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 3.5s cubic-bezier(0.4, 0, 1, 1);
  transform-origin: center left;
  position: absolute;
  top: 0;
  left: 0;
  z-index: 2;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}
.card--front.open {
  transform: rotateY(-180deg);
  box-shadow: 15px 10px 5px rgba(0, 0, 0, 0.3);
}
.card--front.back {
  z-index: 0;
  backface-visibility: visible;
  -webkit-backface-visibility: visible;
}
.card--inner {
  overflow: hidden;
  padding: 15px;
}
.card--inner h2 {
  font-size: 32px;
}
.card--inner img {
  max-width: 60%;
  margin-top: 1.5em;
}
.card--inner.open:before {
  transform: translateX(-155%);
  opacity: 0.1;
}
.card--inner:before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.3);
  z-index: 1;
  opacity: 1;
  transition: all 1s ease-in-out;
}

button {
  -webkit-appearance: none;
  background: #E53935;
  border: 5px solid #9f1815;
  border-width: 0 0 5px;
  padding: 10px 20px;
  width: 150px;
  text-align: center;
  display: block;
  transform: rotateX(30deg);
  margin-top: 20px;
  box-shadow: 0 4px 2px rgba(0, 0, 0, 0.3);
}
button:active {
  border-bottom-width: 2px;
  margin-top: 23px;
  outline: none;
}
button:focus {
  outline: none;
}
<div class="wrap" id="wrap">
  <div class="card card--inner" style="background-color:white;">
 <h2 style="display:inline;width:90%;height:20%;background-color:#8eb9ff;position:absolute;left:3%;top:4%;margin:0px 5px;"></h2>
    <h2 style="display:inline;width:60%;height:10%;background-color:#8eb9ff;position:absolute;left:20%;top:28%;margin:0px 5px;"></h2>
   
    <h2 style="display:inline;width:90%;height:37.5%;background-color:#8eb9ff;position:absolute;left:3%;top:41%;margin:0px 5px;"></h2>
    <h2 style="display:inline;width:30%;height:10%;background-color:#8eb9ff;position:absolute;right:3%;top:84%;margin:0px 5px;"></h2>
  </div>
  <div id="cc" style="background-color:white;" class="card card--front back" onclick="openCard();">
   
     <h2 style="display:inline;width:90%;height:46.5%;background-color:#8eb9ff;position:absolute;left:3%;top:51%;margin:0px 5px;z-index;1000;"></h2>
       <h2 style="display:inline;width:90%;height:46.5%;background-color:#8eb9ff;position:absolute;left:3%;top:3%;margin:0px 5px;z-index;1000;"></h2>
  </div>
  <div class="card card--front" onclick="openCard();">
    <h2 style="display:inline;width:90%;height:20%;background-color:#8eb9ff;position:absolute;left:3.5%;top:4%;margin:0px 5px;"></h2>
    <h2 style="display:inline;width:60%;height:10%;background-color:#8eb9ff;position:absolute;left:20.5%;top:28%;margin:0px 5px;"></h2>
    <h2 style="display:inline;width:80%;height:6%;background-color:#8eb9ff;position:absolute;left:9%;top:43%;margin:0px 5px;"></h2>
    <h2 style="display:inline;width:90%;height:46.5%;background-color:#8eb9ff;position:absolute;left:4%;top:53%;margin:0px 5px;"></h2>
  </div>
</div>

<button type="button" onclick="pers();setTimeout(openCard, 2000);" id="button">Open Card</button>

0 个答案:

没有答案