3D旋转相册

一、效果图

二、代码部分

(1)HTML代码

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>3D旋转相册</title>
    <link rel="stylesheet" href="common.css">
    <style>
        * { margin: 0; padding: 0; }
        body { overflow: hidden; background: #000000; }
        .perspectice { perspective: 800px; }
        .wrap {
            width: 133px;
            height: 200px;
            margin: 150px auto;
            border: none;
            transform-style: preserve-3d;
            transform: rotateX(-20deg) rotateY(0deg);
        }
        .wrap img {
            position: absolute;
            top: 0;
        }
    </style>
</head>
<body>
<div class="perspectice">
    <div class="wrap">
        <img src="images/1.jpeg" width="133px" height="200px">
        <img src="images/2.jpeg" width="133px" height="200px">
        <img src="images/3.jpeg" width="133px" height="200px">
        <img src="images/4.jpeg" width="133px" height="200px">
        <img src="images/5.jpeg" width="133px" height="200px">
        <img src="images/6.jpeg" width="133px" height="200px">
        <img src="images/7.jpeg" width="133px" height="200px">
        <img src="images/8.jpeg" width="133px" height="200px">
        <img src="images/9.jpeg" width="133px" height="200px">
        <img src="images/10.jpeg" width="133px" height="200px">
    </div>
</div>
<script>
    window.onload = function() {
        var oImg = document.getElementsByTagName("img");
        var Deg = 360 / oImg.length;

        Array.prototype.forEach.call(oImg, function(el, index) {
            el.style.transform = "rotateY(" + Deg * index + "deg) translateZ(350px)";
            el.style.transition = "transform 1s " + index * 0.1 + "s";
        });

        var rotation = 0;
        setInterval(function() {
            rotation += 1;
            document.querySelector('.wrap').style.transform = 'rotateX(-20deg) rotateY(' + rotation + 'deg)';
        }, 50);
    };
</script>
</body>
</html>

(2)CSS代码


*{margin: 0;padding: 0;}
body{overflow: hidden;background: #000000;}

.perspectice{
<!--景深 -->
    perspective: 800px;
}
.wrap{
    width: 133px;
    height: 200px;
    border: 1px solid cornflowerblue;
    margin: 150px auto;

    transform-style: preserve-3d;
    transform:rotateX(-20deg) rotateY(0deg);
}
.wrap img{
    position: absolute;
    top: 0;

}

(3)JavaScript代码

window.onload=function() {
    var oImg = document.getElementsByTagName("img");

    var Deg = 360 / oImg.length;

    Array.prototype.forEach.call(oImg, function (el, index) {
        el.style.transform = "rotateY(" + Deg * index + "deg) translateZ(350px)";
        el.style.zIndex = -index;
        el.style.transition = "transform 1s " + index * 0.1 + "s";

    });
}

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值