一.效果预览图
二.实现思路
1.实现旋转木马效果的第一步是先准备好自己需要的图片,创建html文件
2.旋转木马的实现,关键点在3D形变和关键帧动画。文章来源:https://www.toymoban.com/news/detail-629401.html
3.步骤,定义一个div使其居中,,把图片放进div盒子里,因为图片需要3D形变,所以要给div设置3D环境,给图片设置定位或者使用弹性布局使其在相对的位置,要控制图片一定要在div中,否则关键帧动画旋转的时候整体会是倾斜的,根据图片的数量,合理控制图像的旋转角度,(通常使用 360度/图片数量=需要旋转的角度),最后设置z轴的移动距离和关键帧动画。文章来源地址https://www.toymoban.com/news/detail-629401.html
三.相关代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
*{
margin: 0;
padding: 0;
perspective: 500000px;
transform-style: preserve-3d;
}
.wp{
width: 800px;
height: 400px;
perspective: 500000px;
transform-style: preserve-3d;
position: relative;
margin: 200px auto;
animation: xz 10s infinite linear;
}
img{
width: 180px;
height: 300px;
position: absolute;
left: 310PX;
}
.wp img:nth-child(1){
transform: rotateY(0) translateZ(400px);
}
.wp img:nth-child(2){
transform: rotateY(-30deg) translateZ(400px);
}
.wp img:nth-child(3){
transform: rotateY(-60deg) translateZ(400px);
}
.wp img:nth-child(4){
transform: rotateY(-90deg) translateZ(400px);
}
.wp img:nth-child(5){
transform: rotateY(-120deg) translateZ(400px);
}
.wp img:nth-child(6){
transform: rotateY(-150deg) translateZ(400px);
}
.wp img:nth-child(7){
transform: rotateY(-180deg) translateZ(400px);
}
.wp img:nth-child(8){
transform: rotateY(-210deg) translateZ(400px);
}
.wp img:nth-child(9){
transform: rotateY(-240deg) translateZ(400px);
}
.wp img:nth-child(10){
transform: rotateY(-270deg) translateZ(400px);
}
.wp img:nth-child(11){
transform: rotateY(-300deg) translateZ(400px);
}
.wp img:nth-child(12){
transform: rotateY(-330deg) translateZ(400px);
}
@keyframes xz{
0%{
transform: rotateX(-10deg);
}
100%{
transform: rotateX(-10deg) rotateY(360deg);
}
}
</style>
</head>
<body>
<div class="wp">
<img src="./image/wallhaven-pkgkkp.png" alt="">
<img src="./image/wallhaven-pkgkkp.png" alt="">
<img src="./image/wallhaven-pkgkkp.png" alt="">
<img src="./image/wallhaven-pkgkkp.png" alt="">
<img src="./image/wallhaven-pkgkkp.png" alt="">
<img src="./image/wallhaven-pkgkkp.png" alt="">
<img src="./image/wallhaven-pkgkkp.png" alt="">
<img src="./image/wallhaven-pkgkkp.png" alt="">
<img src="./image/wallhaven-pkgkkp.png" alt="">
<img src="./image/wallhaven-pkgkkp.png" alt="">
<img src="./image/wallhaven-pkgkkp.png" alt="">
<img src="./image/wallhaven-pkgkkp.png" alt="">
</div>
</body>
</html>
到了这里,关于前端小练习:案例4.3D图片旋转展示(旋转木马)的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!