HTML实现3D照片旋转墙

html 复制代码
<!DOCTYPE html>
<html lang="en" ondragstart="return false">

<head>
      <meta charset="UTF-8">
      <meta name="Keywords" content="">
      <meta name="Description" content="">
      <title>3D旋转照片墙</title>
      <!-- 如果我有天醒来 -->
      <!-- 层叠样式表 -->
      <style type="text/css">
            /* 去掉默认效果 */
            * {
                  margin: 0;
                  padding: 0;
            }

            body {
                  background: #222;
                  overflow: hidden;
                  /* 取消选中 */
                  user-select: none;

            }

            @keyframes rotate {
                  100% {
                        transform: rotateY(360deg);
                  }
            }

            .perspective {
                  /*子元素透视 场景深度*/
                  perspective: 600px;
            }

            .wrap {
                  /* 3d */
                  width: 135px;
                  height: 240px;
                  margin: 100px auto;
                  position: relative;
                  /* border: 1px solid red; */
                  transform: rotateX(-20deg) rotateY(0deg);
                  transform-style: preserve-3d;

            }

            .wrap img {
                  display: block;
                  /* 绝对定位 */
                  position: absolute;
                  width: 100%;
                  height: 100%;
                  transform: rotateY(0deg) translateZ(0px);
                  background: transparent;
                  box-shadow: 0 0 4px #fff;
                  border-radius: 5px;

                  /* webkit */
            }

            /* 照片底座 */
            .wrap p {
                  width: 1200px;
                  height: 1200px;
                  background: -webkit-radial-gradient(center center, 600px 600px, rgba(122, 122, 122, .5), rgba(0, 0, 0, 0));
                  position: absolute;
                  border-radius: 50%;
                  left: 50%;
                  top: 100%;
                  margin-left: -600px;
                  margin-top: -600px;
                  /* 沿着x轴按倒 */
                  transform: rotateX(90deg);

            }
      </style>
</head>

<body>
      <!-- 盒子容器 -->
      <div class="perspective">
            <div class="wrap" id="imgwrap">
                  <!-- 引入图片值页面 -->
                  <img class="f1" src="img/12.jpg" />
                  <img class="f1" src="img/13.jpg" />
                  <img class="f1" src="img/14.jpg" />
                  <img class="f1" src="img/15.jpg" />
                  <img class="f1" src="img/16.jpg" />
                  <img class="f1" src="img/1.jpg" />
                  <img class="f1" src="img/2.jpg" />
                  <img class="f1" src="img/3.jpg" />
                  <img class="f1" src="img/4.jpg" />
                  <img class="f1" src="img/5.jpg" />
                  <img class="f1" src="img/6.jpg" />
                  <img class="f1" src="img/7.jpg" />
                  <img class="f1" src="img/5.jpg" />
                  <img class="f1" src="img/6.jpg" />
                  <img class="f1" src="img/7.jpg" />
                  <img class="f1" src="img/8.jpg" />
                  <img class="f1" src="img/9.jpg" />
                  <img class="f1" src="img/10.jpg" />
                  <img class="f1" src="img/11.jpg" />

                  <img class="f1" src="img/17.jpg" />
                  <img class="f1" src="img/18.jpg" />
                  <img class="f1" src="img/19.jpg" />
                  <img class="f1" src="img/20.jpg" />
                  <img class="f1" src="img/21.jpg" />
                  <img class="f1" src="img/22.jpg" />
                  <img class="f1" src="img/23.jpg" />
                  <img class="f1" src="img/24.jpg" />
                  <img class="f1" src="img/25.jpg" />
                  <img class="f1" src="img/26.jpg" />
                  <img class="f1" src="img/27.jpg" />
                  <img class="f1" src="img/28.jpg" />
                  <img class="f1" src="img/29.jpg" />
                  <img class="f1" src="img/30.jpg" />

                  <!-- 引入图片值页面 -->
                  <img class="f2" src="img/1.jpg" />
                  <img class="f2" src="img/2.jpg" />
                  <img class="f2" src="img/3.jpg" />
                  <img class="f2" src="img/4.jpg" />
                  <img class="f2" src="img/5.jpg" />

                  <img class="f2" src="img/9.jpg" />
                  <img class="f2" src="img/10.jpg" />
                  <img class="f2" src="img/11.jpg" />
                  <img class="f2" src="img/12.jpg" />
                  <img class="f2" src="img/25.jpg" />
                  <img class="f2" src="img/26.jpg" />
                  <img class="f2" src="img/27.jpg" />
                  <img class="f2" src="img/28.jpg" />
                  <img class="f2" src="img/29.jpg" />
                  <img class="f2" src="img/30.jpg" />
                  <img class="f2" src="img/13.jpg" />
                  <img class="f2" src="img/14.jpg" />
                  <img class="f2" src="img/15.jpg" />
                  <img class="f2" src="img/16.jpg" />
                  <img class="f2" src="img/17.jpg" />
                  <img class="f2" src="img/18.jpg" />
                  <img class="f2" src="img/19.jpg" />
                  <img class="f2" src="img/20.jpg" />
                  <img class="f2" src="img/21.jpg" />
                  <img class="f2" src="img/22.jpg" />
                  <img class="f2" src="img/23.jpg" />
                  <img class="f2" src="img/24.jpg" />
                  <img class="f2" src="img/6.jpg" />
                  <img class="f2" src="img/7.jpg" />
                  <img class="f2" src="img/5.jpg" />
                  <img class="f2" src="img/6.jpg" />
                  <img class="f2" src="img/7.jpg" />
                  <img class="f2" src="img/8.jpg" />
                  <!-- 引入图片值页面 -->

                  <img class="f3" src="img/1.jpg" />
                  <img class="f3" src="img/2.jpg" />
                  <img class="f3" src="img/11.jpg" />
                  <img class="f3" src="img/12.jpg" />
                  <img class="f3" src="img/25.jpg" />
                  <img class="f3" src="img/26.jpg" />
                  <img class="f3" src="img/27.jpg" />
                  <img class="f3" src="img/3.jpg" />
                  <img class="f3" src="img/4.jpg" />
                  <img class="f3" src="img/5.jpg" />


                  <img class="f3" src="img/16.jpg" />
                  <img class="f3" src="img/17.jpg" />
                  <img class="f3" src="img/18.jpg" />
                  <img class="f3" src="img/10.jpg" />

                  <img class="f3" src="img/28.jpg" />
                  <img class="f3" src="img/29.jpg" />
                  <img class="f3" src="img/30.jpg" />
                  <img class="f3" src="img/13.jpg" />

                  <img class="f3" src="img/19.jpg" />
                  <img class="f3" src="img/20.jpg" />
                  <img class="f3" src="img/21.jpg" />
                  <img class="f3" src="img/22.jpg" />
                  <img class="f3" src="img/23.jpg" />
                  <img class="f3" src="img/24.jpg" />
                  <img class="f3" src="img/9.jpg" />
                  <img class="f3" src="img/14.jpg" />
                  <img class="f3" src="img/15.jpg" />
                  <img class="f3" src="img/6.jpg" />
                  <img class="f3" src="img/7.jpg" />
                  <img class="f3" src="img/5.jpg" />
                  <img class="f3" src="img/6.jpg" />
                  <img class="f3" src="img/7.jpg" />
                  <img class="f3" src="img/8.jpg" />


                  <p></p>
            </div>
      </div>
      <!--  src="JS/photo.js" -->
      <script type="text/javascript">
            var oImg = document.getElementsByClassName('f1')
            var oImg2 = document.getElementsByClassName('f2')
            var oImg3 = document.getElementsByClassName('f3')
            var len = oImg.length;
            console.log(len)
            var deg = 360 / len;

            var oWrap = document.getElementById("imgwrap");
            // var oWrap=document.querySelector('.wrap');

            //页面加载完毕在执行的代码
            window.onload = function () {
                  Array.prototype.forEach.call(oImg, function (ele, index, self) {
                        // 旋转并沿Z轴平移
                        ele.style.transform = "rotateY(" + deg * index + "deg) translateZ(645.75px)";
                        //过渡时间1s
                        ele.style.transition = "1s " + (len - index) * 0.1 + "s";

                  });
                  Array.prototype.forEach.call(oImg2, function (ele, index, self) {
                        // 旋转并沿Z轴平移
                        ele.style.transform = "rotateY(" + deg * index + "deg) translateZ(645.75px) translateY(240px)";
                        //过渡时间1s
                        ele.style.transition = "1s " + (len - index) * 0.1 + "s";

                  });
                  Array.prototype.forEach.call(oImg3, function (ele, index, self) {
                        // 旋转并沿Z轴平移
                        ele.style.transform = "rotateY(" + deg * index + "deg) translateZ(645.75px) translateY(480px)";
                        //过渡时间1s
                        ele.style.transition = "1s " + (len - index) * 0.1 + "s";

                  });
                  // Array.prototype.forEach.call(oImg, function (ele, index, self) {
                  //       // 旋转并沿Z轴平移
                  //       ele.style.transform = "rotateY(" + deg * index + "deg) translateZ(350px)";
                  //       //过渡时间1s
                  //       ele.style.transition = "1s " + (len - index) * 0.1 + "s";

                  // });

            }
            //翻动3D相册
            var newX, newY, lastX, lastY, minusX, minusY, rotX = -20, rotY = 0;

            document.onmousedown = function (e) {
                  // 点击设置初值
                  lastX = e.clientX;
                  lastY = e.clientY;

                  this.onmousemove = function (e) {
                        newX = e.clientX;
                        newY = e.clientY;
                        minusX = newX - lastX;
                        minusY = newY - lastY;

                        rotX -= minusY * 0.2;
                        rotY += minusX * 0.1;
                        oWrap.style.transform = "rotateX(" + rotX + "deg) rotateY(" + rotY + "deg)";
                        lastX = newX;
                        lastY = newY;

                  }
                  this.onmouseup = function (e) {
                        //鼠标松开
                        this.onmousemove = null;//清除鼠标移动
                  }
            }

      </script>
</body>

</html>
相关推荐
桃园码工14 分钟前
15_HTML5 表单属性 --[HTML5 API 学习之旅]
前端·html5·表单属性
百万蹄蹄向前冲1 小时前
2024不一样的VUE3期末考查
前端·javascript·程序员
轻口味1 小时前
【每日学点鸿蒙知识】AVCodec、SmartPerf工具、web组件加载、监听键盘的显示隐藏、Asset Store Kit
前端·华为·harmonyos
alikami1 小时前
【若依】用 post 请求传 json 格式的数据下载文件
前端·javascript·json
吃杠碰小鸡2 小时前
lodash常用函数
前端·javascript
emoji1111112 小时前
前端对页面数据进行缓存
开发语言·前端·javascript
泰伦闲鱼2 小时前
nestjs:GET REQUEST 缓存问题
服务器·前端·缓存·node.js·nestjs
m0_748250032 小时前
Web 第一次作业 初探html 使用VSCode工具开发
前端·html
一个处女座的程序猿O(∩_∩)O2 小时前
vue3 如何使用 mounted
前端·javascript·vue.js
m0_748235952 小时前
web复习(三)
前端