代码很简单,大概 思路:
1, 添加图片, 设置position, 图片叠加, 共用一个中心点;
2, 图片设置y轴旋转, 共9张, 一圈360°, 每张依次旋转+=40°, 第一张旋转0°;
3, 将图片拉开排布, 设置translateZ( );
4, 添加点击事件, 让图片动起来.
话不多说,看代码吧
1, 结构
<body>
<div class="wrap">
<div id="content">
<img src="image/1.jpg" alt="" />
<img src="image/2.jpeg" alt="" />
<img src="image/3.jpeg" alt="" />
<img src="image/4.jpeg" alt="" />
<img src="image/5.jpg" alt="" />
<img src="image/6.jpg" alt="" />
<img src="image/7.jpg" alt="" />
<img src="image/8.jpg" alt="" />
<img src="image/9.jpg" alt="" />
</div>
</div>
</body>
2, 样式
<style media="screen">
/*图片大小*/
img {
width: 140px;
height: 110px;
position: absolute;
}
.wrap {
width: 100px;
margin: 0 auto;
margin-top: 100px;
-webkit-perspective: 800px;
}
#content {
-webkit-transform-style:preserve-3d;
transition: 2s;
}
/*图片旋转*/
img:nth-child(1) {
transform: rotateY(0deg) translateZ(220px);
}
img:nth-child(2) {
transform: rotateY(40deg) translateZ(220px);
}
img:nth-child(3) {
transform: rotateY(80deg) translateZ(220px);
}
img:nth-child(4) {
transform: rotateY(120deg) translateZ(220px);
}
img:nth-child(5) {
transform: rotateY(160deg) translateZ(220px);
}
img:nth-child(6) {
transform: rotateY(200deg) translateZ(220px);
}
img:nth-child(7) {
transform: rotateY(240deg) translateZ(220px);
}
img:nth-child(8) {
transform: rotateY(280deg) translateZ(220px);
}
img:nth-child(9) {
transform: rotateY(320deg) translateZ(220px);
}
</style>
3, javaScript
<script type="text/javascript">
var content = document.getElementById('content');
var angel = 40;
//添加点击事件让图片旋转
content.onclick = function () {
content.style.transform = 'rotateY('+angel+'deg)';
angel += 40;
}
</script>
网友评论