|
| 1 | +const cubeRoom = document.getElementById('cube-room'); |
| 2 | +const centerWall = document.getElementById('center-wall'); |
| 3 | +const resetBtn = document.getElementById('reset-bg-btn'); |
| 4 | +const walls = document.querySelectorAll('.wall-grid'); |
| 5 | + |
| 6 | +// Generate Foto Otomatis ke Dinding Samping |
| 7 | +walls.forEach((wall) => { |
| 8 | + const wallType = wall.getAttribute('data-wall'); |
| 9 | + |
| 10 | + for (let i = 0; i < 12; i++) { |
| 11 | + const imgUrl = `https://picsum.photos/800/600?random=${Math.floor(Math.random() * 10000)}`; |
| 12 | + |
| 13 | + const img = document.createElement('img'); |
| 14 | + img.src = imgUrl; |
| 15 | + img.classList.add('photo-item'); |
| 16 | + |
| 17 | + // Eksekusi Klik Gambar |
| 18 | + img.addEventListener('click', (e) => { |
| 19 | + e.stopPropagation(); |
| 20 | + |
| 21 | + // Efek kamera bergerak halus mendekat ke arah dinding yang diklik |
| 22 | + if (wallType === 'left') cubeRoom.style.transform = "rotateY(-15deg) translateZ(80px)"; |
| 23 | + if (wallType === 'right') cubeRoom.style.transform = "rotateY(15deg) translateZ(80px)"; |
| 24 | + if (wallType === 'top') cubeRoom.style.transform = "rotateX(-10deg) translateZ(80px)"; |
| 25 | + if (wallType === 'bottom') cubeRoom.style.transform = "rotateX(10deg) translateZ(80px)"; |
| 26 | + |
| 27 | + // Langsung update background di sekat tengah |
| 28 | + centerWall.style.backgroundImage = `url('${imgUrl}')`; |
| 29 | + centerWall.classList.add('has-bg'); |
| 30 | + centerWall.style.borderColor = "#fff"; |
| 31 | + resetBtn.style.display = "inline-block"; |
| 32 | + |
| 33 | + // Kamera otomatis reset lurus fokus ke tengah lagi secara smooth |
| 34 | + setTimeout(() => { |
| 35 | + cubeRoom.style.transform = "rotateX(0deg) rotateY(0deg) translateZ(0px)"; |
| 36 | + }, 600); |
| 37 | + }); |
| 38 | + |
| 39 | + wall.appendChild(img); |
| 40 | + } |
| 41 | +}); |
| 42 | + |
| 43 | +// Tombol Reset Background |
| 44 | +resetBtn.addEventListener('click', (e) => { |
| 45 | + e.stopPropagation(); |
| 46 | + centerWall.style.backgroundImage = "none"; |
| 47 | + centerWall.classList.remove('has-bg'); |
| 48 | + centerWall.style.borderColor = "rgba(255, 255, 255, 0.1)"; |
| 49 | + resetBtn.style.display = "none"; |
| 50 | + cubeRoom.style.transform = "rotateX(0deg) rotateY(0deg) translateZ(0px)"; |
| 51 | +}); |
0 commit comments