3D輪播照片墻是一個很酷的網頁效果,讓你把照片展示在一個立體的墻面上,可以用于展示圖片集合、產品演示、婚紗照等。下面是一個3D輪播照片墻的HTML代碼示例。
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>3D輪播照片墻</title> <style> .carousel { width: 100%; height: 500px; perspective: 1200px; perspective-origin: 50% 50%; } .carousel-slide { width: 100%; height: 100%; position: relative; transform-style: preserve-3d; } .carousel-slide img { position: absolute; width: 300px; height: 400px; left: 0; top: 0; transform-style: preserve-3d; transform: translateZ(0); box-shadow: 0px 2px 5px rgba(0,0,0,0.2); } .carousel-slide img:nth-child(1) { transform: rotateY(0deg) translateZ(250px); opacity: 1; } .carousel-slide img:nth-child(2) { transform: rotateY(60deg) translateZ(250px); opacity: 0.8; } .carousel-slide img:nth-child(3) { transform: rotateY(120deg) translateZ(250px); opacity: 0.6; } .carousel-slide img:nth-child(4) { transform: rotateY(180deg) translateZ(250px); opacity: 0.8; } .carousel-slide img:nth-child(5) { transform: rotateY(240deg) translateZ(250px); opacity: 1; } .carousel-slide img:nth-child(6) { transform: rotateY(300deg) translateZ(250px); opacity: 0.8; } .carousel-slide img:nth-child(7) { transform: rotateY(360deg) translateZ(250px); opacity: 0.6; } .carousel-slide .carousel-control { position: absolute; top: 50%; transform: translateY(-50%); color: #fff; font-size: 2rem; cursor: pointer; z-index: 999; } .carousel-slide .carousel-control.left { left: 1rem; } .carousel-slide .carousel-control.right { right: 1rem; } </style> </head> <body> <div class="carousel"> <div class="carousel-slide"> <img src="1.jpg" alt=""> <img src="2.jpg" alt=""> <img src="3.jpg" alt=""> <img src="4.jpg" alt=""> <img src="5.jpg" alt=""> <img src="6.jpg" alt=""> <img src="7.jpg" alt=""> <div class="carousel-control left">< </div> <div class="carousel-control right">> </div> </div> </div> <script> let carousel = document.querySelector('.carousel'); let slide = document.querySelector('.carousel-slide'); let prevBtn = document.querySelector('.carousel-control.left'); let nextBtn = document.querySelector('.carousel-control.right'); let rotateY = 0; prevBtn.addEventListener('click', () => { rotateY += 60; slide.style.transform = `rotateY(${rotateY}deg)`; }); nextBtn.addEventListener('click', () => { rotateY -= 60; slide.style.transform = `rotateY(${rotateY}deg)`; }); </script> </body> </html>
上面的代碼使用了HTML、CSS、JavaScript三種語言,在HTML中創建了一個div容器,包含一個帶有多個img標簽的輪播墻,用CSS設置了輪播墻的基本樣式,包括墻體大小、透視角度等,以及照片的位置、大小、透明度等,JavaScript通過控制墻體的旋轉來實現輪播的功能。