HTML5+CSS3+JS小实例:图片九宫格
以下是一个简单的HTML5、CSS3和JavaScript代码示例,实现了一个图片九宫格效果。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>图片九宫格</title>
<style>
.container {
width: 300px;
height: 300px;
perspective: 1000px;
margin: 50px auto;
position: relative;
}
.container .cube {
width: 100%;
height: 100%;
transform-style: preserve-3d;
transition: transform 1s;
}
.container .face {
position: absolute;
width: 100%;
height: 100%;
box-shadow: 0 0 5px #000;
line-height: 100px;
text-align: center;
font-size: 3em;
color: #fff;
}
.face1 {
background: url('img/1.jpg');
background-size: cover;
}
.face2 {
background: url('img/2.jpg');
background-size: cover;
transform: rotateY(90deg) translateZ(100px);
}
.face3 {
background: url('img/3.jpg');
background-size: cover;
transform: rotateY(-90deg) translateZ(100px);
}
.face4 {
background: url('img/4.jpg');
background-size: cover;
transform: rotateX(90deg) translateZ(100px);
}
.face5 {
background: url('img/5.jpg');
background-size: cover;
transform: rotateX(-90deg) translateZ(100px);
}
.face6 {
background: url('img/6.jpg');
background-size: cover;
transform: rotateY(180deg) translateZ(100px);
}
.face7 {
background: url('img/7.jpg');
background-size: cover;
transform: translateZ(-100px);
}
.face8 {
background: url('img/8.jpg');
background-size: cover;
transform: rotateY(90deg) translateZ(-100px);
}
.face9 {
background: url('img/9.jpg');
background-size: cover;
transform: rotateY(-90deg) translateZ(-100px);
}
</style>
</head>
<body>
<div class="container">
<div class="cube">
<div class="face face1">1</div>
<div class="face face2">2</div>
<div class="face face3">3</div>
<div class="face face4">4</div>
<div class="face face5">5</div>
<div class="face face6">6</div>
<div class="face face7">7</div>
<div class="face face8">8</div>
<div class="face face9">9</div>
</div>
</div>
<script>
const cube = document.querySel
评论已关闭