gpt4 book ai didi

html - 如何使用 CSS 在 3d 中旋转两个图像?

转载 作者:太空宇宙 更新时间:2023-11-04 02:46:28 25 4
gpt4 key购买 nike

我正在尝试使用 CSS 实现这个 3D 几何变换示例:

3D Geometric Transform

但是我的动画不像那个例子那样工作,这就是我所拥有的:

<!DOCTYPE html>
<html>
<head>
<meta charset ="utf-8">
<title>Test</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" integrity="sha512-dTfge/zgoMYpP7QbHy4gWMEGsbsdZeCXz7irItjcC3sPUFtf0kuFbDz/ixG7ArTxmDjLXDmezHubeNikyKGVyQ==" crossorigin="anonymous">
</head>

<body>
<style>
#im1 { transform: translateZ(25px); }
#im2 { transform: translateZ(-25px); transform: translateY(-50px); }
#obj1 {
animation: theRotate 2s linear infinite;
perspective: 1000px;
transform-style: preserve-3d;}

@keyframes theRotate
{
from {transform: rotateY(0deg) }
to {transform: rotateY(360deg) }
}
</style>

<div class="container">
<div class="row">

<div class="col-sm-1 col-md-1" id="obj1">
<img src="wicon2.png" id="im1" style="width:50px">
<img src="wicon.png" id="im2" style="width:50px">
</div>

</div>
</div>


</body>
</html>

根据 this ,使用 perspective:1000 动画应该可以正常工作,但事实并非如此。

如果有另一种简单的方法来做到这一点,也许用 JS,也可以。

非常感谢您抽出时间,谢谢。

最佳答案

我查看了您发布的初始链接/示例,并从那里复制了相关的 CSS 代码,并将其改编为您现有的代码。您发布的代码的以下编辑应该以预期的方式工作(如链接示例所示)。

请注意:如果您运行下面的代码片段,它将旋转空图像,因为图像链接与您的帖子 (wicon1.png) 相同

<html>
<head>
<meta charset ="utf-8">
<title>Test</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" integrity="sha512-dTfge/zgoMYpP7QbHy4gWMEGsbsdZeCXz7irItjcC3sPUFtf0kuFbDz/ixG7ArTxmDjLXDmezHubeNikyKGVyQ==" crossorigin="anonymous">
</head>

<body>
<style>

.scene3d
{
perspective: 1000px;
width: 600px;
height: 340px;
margin-left: auto;
margin-right: auto;
}
.object3d
{
position: absolute;
width: inherit;
height: inherit;
/*top: 20px;*/
transform-style: preserve-3d;
}
.face3d
{
position: absolute;
left: 165px;
top: 15px;
}

#im1 { transform: translateZ(150px); }
#im2 { transform: translateZ(-150px); }
.scene3d.begin { perspective: 100000px; }
.scene3d.end { perspective: 1000px; }
#obj1 { animation: theRotate 4s linear infinite; }

@keyframes theRotate
{
from {transform: rotateY(0deg);}
to {transform: rotateY(360deg);}
}



</style>

<div class="container">
<div class="row scene3d">

<div class="col-sm-1 col-md-1 object3d" id="obj1">
<img src="wicon1.png" id="im1" class="face3d" style="width:50px">
<img src="wicon2.png" id="im2" class="face3d" style="width:50px">
</div>

</div>
</div>


</body>
</html>

关于html - 如何使用 CSS 在 3d 中旋转两个图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33783955/

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