如何使用CSS3创建3D透视图?

Har*_*vey 5 html css3

我一直在努力为我一直在研究的项目创建一个3D外观卡片翻转动画类型.不幸的是,我的动画并不完全是3D.

我一直在使用本指南.在第一个例子中,这个人设法使它看起来像窗户背景翻转.但是,当我尝试在JSFiddle上使用相同的代码时,结果与他的不一样.

他的演示代码在下面产生了效果.当卡被翻转时,它会使一侧变小,给人以透视的印象: 在此输入图像描述

在我的JSFiddle上使用他的代码(除了不同的背景),两边看起来在整个时间内保持相同的大小: 在此输入图像描述

有人可以向我解释我错过了什么,或者如何在他的网站上获得相同的透视效果?提前致谢.

他的HTML代码:

<div id="f1_container">
<div id="f1_card" class="shadow">
  <div class="front face">
    <img src="/images/Windows%20Logo.jpg"/>
  </div>
  <div class="back face center">
    <p>This is nice for exposing more information about an image.</p>
    <p>Any content can go here.</p>
  </div>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)

他的CSS代码:

#f1_container {
  position: relative;
  margin: 10px auto;
  width: 450px;
  height: 281px;
  z-index: 1;
}
#f1_container {
  perspective: 1000;
}
#f1_card {
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transition: all 1.0s linear;
}
#f1_container:hover #f1_card {
  transform: rotateY(180deg);
  box-shadow: -5px 5px 5px #aaa;
}
.face {
  position: absolute;
  width: 100%;
  height: 100%;
  backface-visibility: hidden;
}
.face.back {
  display: block;
  transform: rotateY(180deg);
  box-sizing: border-box;
  padding: 10px;
  color: white;
  text-align: center;
  background-color: #aaa;
}
Run Code Online (Sandbox Code Playgroud)

use*_*143 3

看到他在哪里说他从 CSS 中删除了供应商前缀以保持简洁吗?我敢打赌这就是你的问题。其中一些 CSS 属性并不完全标准,而是在具有不同供应商前缀的不同浏览器中实现。我实际上不确定是哪些,但 Google 可以提供帮助。

编辑:嗯。好吧,CSS 无论如何都是罪魁祸首,但我实际上并没有看到很多供应商前缀。我将他的实际 CSS 从页面上拉下来,并将其粘贴到您使用的“干净”CSS 的位置,这使得小提琴可以工作。他真正的CSS是:

#f1_container {
    height: 281px;
    margin: 10px auto;
    position: relative;
    width: 450px;
    z-index: 1;
}
#f1_container {
    perspective: 1000px;
}
#f1_card {
    height: 100%;
    transform-style: preserve-3d;
    transition: all 1s linear 0s;
    width: 100%;
}
#f1_container:hover #f1_card, #f1_container.hover_effect #f1_card {
    box-shadow: -5px 5px 5px #AAAAAA;
    transform: rotateY(180deg);
}
.face {
    backface-visibility: hidden;
    height: 100%;
    position: absolute;
    width: 100%;
}
.face.back {
    -moz-box-sizing: border-box;
    background-color: #AAAAAA;
    color: #FFFFFF;
    display: block;
    padding: 10px;
    text-align: center;
    transform: rotateY(180deg);
}
Run Code Online (Sandbox Code Playgroud)