dos
HTML:
copy HTML
<base href="scripte/img/content/img_m_01.jpg"> <div id="carousel"> <figure id="spinner"> <img src="img_m_01.jpg" alt> <img src="img_m_02.jpg" alt> <img src="img_m_03.jpg" alt> <img src="img_m_04.jpg" alt> <img src="img_m_05.jpg" alt> <img src="img_m_06.jpg" alt> <img src="img_m_07.jpg" alt> <img src="img_m_08.jpg" alt> </figure> </div> <span class="carousel-icon carousel-icon-left" onclick="galleryspin('-')"><</span> <span class="carousel-icon carousel-icon-right" onclick="galleryspin('')">></span>
CSS:
copy CSS
* { box-sizing: border-box; } body { margin: 0; height: 100vh; display: flex; align-items: center; justify-content: center; background: radial-gradient(circle, #1e1e1e, #000); font-family: sans-serif; color: white; } .container { position: relative; text-align: center; } div#carousel { position: relative; perspective: 1200px; padding-top: 10%; font-size: 0; margin-bottom: 3rem; overflow: visible; /* war vorher: hidden */ width: 100%; max-width: 900px; margin-left: auto; margin-right: auto; } figure#spinner { transform-style: preserve-3d; height: 300px; transform-origin: 50% 50% -500px; transition: 1s; position: relative; } figure#spinner img { width: 40%; max-width: 425px; position: absolute; left: 30%; transform-origin: 50% 50% -500px; outline: 1px solid transparent; border-radius: 8px; box-shadow: 0 10px 20px rgba(0, 0, 0, 0.5); } figure#spinner img:nth-child(1) { transform: rotateY(0deg); } figure#spinner img:nth-child(2) { transform: rotateY(45deg); } figure#spinner img:nth-child(3) { transform: rotateY(90deg); } figure#spinner img:nth-child(4) { transform: rotateY(135deg); } figure#spinner img:nth-child(5) { transform: rotateY(180deg); } figure#spinner img:nth-child(6) { transform: rotateY(225deg); } figure#spinner img:nth-child(7) { transform: rotateY(270deg); } figure#spinner img:nth-child(8) { transform: rotateY(315deg); } .carousel-icon { position: absolute; top: 50%; transform: translateY(-50%); font-size: 3rem; color: white; cursor: pointer; user-select: none; z-index: 10; transition: 0.3s; } .carousel-icon:hover { color: #aaa; } .carousel-icon-left { left: 1.5rem; } .carousel-icon-right { right: 1.5rem; } /* Responsive Anpassungen */ @media (max-width: 768px) { figure#spinner { height: 220px; } figure#spinner img { width: 60%; left: 20%; } .carousel-icon { font-size: 2.5rem; } .carousel-icon-left { left: 1rem; } .carousel-icon-right { right: 1rem; } } @media (max-width: 480px) { figure#spinner { height: 180px; } figure#spinner img { width: 80%; left: 10%; } .carousel-icon { font-size: 2rem; } }
JavaScript:
copy JS
var angle = 0; function galleryspin(sign) { const spinner = document.querySelector("#spinner"); if (!sign || sign === '+') { angle -= 45; } else { angle += 45; } spinner.setAttribute("style", "-webkit-transform: rotateY(" + angle + "deg); " + "-moz-transform: rotateY(" + angle + "deg); " + "transform: rotateY(" + angle + "deg);" ); } // Keyboard-Pfeiltasten aktivieren document.addEventListener("keydown", function(event) { if (event.key === "ArrowRight") { galleryspin('+'); } else if (event.key === "ArrowLeft") { galleryspin('-'); } });