html3d旋转相册照片
时间: 2023-11-17 07:04:22 浏览: 91
3D旋转相册.html
以下是一个使用HTML和CSS实现的3D旋转相册的示例代码,你可以将其中的照片替换为自己的照片并按照对应的名称命名即可实现自定义的相册效果。
```html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>3D相册</title>
<style>
.container {
width: 500px;
height: 500px;
margin: 0 auto;
position: relative;
perspective: 1000px;
}
.photo {
position: absolute;
width: 400px;
height: 400px;
top: 50px;
left: 50px;
background-size: cover; background-position: center;
transform-style: preserve-3d;
transition: transform 1s;
}
.photo:nth-child(1) {
transform: rotateY(0deg) translateZ(250px);
}
.photo:nth-child(2) {
transform: rotateY(60deg) translateZ(250px);
}
.photo:nth-child(3) {
transform: rotateY(120deg) translateZ(250px);
}
.photo:nth-child(4) {
transform: rotateY(180deg) translateZ(250px);
}
.photo:nth-child(5) {
transform: rotateY(240deg) translateZ(250px);
}
.photo:nth-child(6) {
transform: rotateY(300deg) translateZ(250px);
}
.btn {
position: absolute;
top: 0;
left: 50%;
transform: translateX(-50%);
z-index: 1;
}
.btn button {
margin: 10px;
padding: 5px 10px;
border: none;
background-color: #fff;
color: #000;
cursor: pointer;
}
.btn button:hover {
background-color: #000;
color: #fff;
}
</style>
</head>
<body>
<div class="container">
<div class="photo" style="background-image: url('photo1.jpg');"></div>
<div class="photo" style="background-image: url('photo2.jpg');"></div>
<div class="photo" style="background-image: url('photo3.jpg');"></div>
<div class="photo" style="background-image: url('photo4.jpg');"></div>
<div class="photo" style="background-image: url('photo5.jpg');"></div>
<div class="photo" style="background-image: url('photo6.jpg');"></div>
</div>
<div class="btn">
<button onclick="rotateLeft()">左旋转</button>
<button onclick="rotateRight()">右旋转</button>
<button onclick="rotateUp()">上旋转</button>
<button onclick="rotateDown()">下旋转</button>
</div>
<script>
var container = document.querySelector('.container');
var photos = document.querySelectorAll('.photo');
var rotateY = 0;
var rotateX = 0;
function rotateLeft() {
rotateY -= 60;
container.style.transform = 'rotateY(' + rotateY + 'deg) rotateX(' + rotateX + 'deg)';
}
function rotateRight() {
rotateY += 60;
container.style.transform = 'rotateY(' + rotateY + 'deg) rotateX(' + rotateX + 'deg)';
}
function rotateUp() {
rotateX += 60;
container.style.transform = 'rotateY(' + rotateY + 'deg) rotateX(' + rotateX + 'deg)';
}
function rotateDown() {
rotateX -= 60;
container.style.transform = 'rotateY(' + rotateY + 'deg) rotateX(' + rotateX + 'deg)';
}
</script>
</body>
</html>
```
阅读全文