gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-29 15:56:33 27 4
gpt4 key购买 nike

我一直在尝试为我一直从事的元素创建一个 3D 外观的卡片翻转类型的动画。不幸的是,我的动画看起来并不完全是 3D。

我一直在使用这个 guide .在第一个例子中,这个人设法让它看起来像 Windows 背景正在翻转。但是,当我尝试在 JSFiddle 上使用相同的代码时结果和他的不一样。

他的demo代码做了如下效果。当卡片被翻转时,它会导致一侧变小,给人一种透视的印象: enter image description here

在我的 JSFiddle 上使用他的代码(除了不同的背景),边似乎一直保持相同的大小: enter image description here

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

他的 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>

他的 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;
}

最佳答案

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

编辑:嗯。好吧,无论如何 CSS 是罪魁祸首,但我实际上并没有看到很多供应商前缀。我将他的实际 CSS 从页面上拉下来,并将其粘贴到您使用的“干净”CSS 的位置,这使得 fiddle 可以正常工作。他真正的 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);
}

关于html - 如何使用 CSS3 创建 3D 透视图?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19989054/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com