<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Flip Book</title>
<style>
body {
font-family: Arial, sans-serif;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
background-color: #f0f0f0;
}
.book-container {
perspective: 1500px;
width: 400px;
height: 300px;
position: relative;
}
.page {
width: 100%;
height: 100%;
background: #ffffff;
border: 1px solid #ddd;
position: absolute;
transform-origin: left;
transform-style: preserve-3d;
backface-visibility: hidden;
transition: transform 0.8s ease-in-out;
}
.page:nth-child(1) { background: #ff5722; color: white; z-index: 5; }
.page:nth-child(2) { background: #ff9800; color: white; z-index: 4; }
.page:nth-child(3) { background: #4caf50; color: white; z-index: 3; }
.page:nth-child(4) { background: #2196f3; color: white; z-index: 2; }
.page:nth-child(5) { background: #9c27b0; color: white; z-index: 1; }
/* Tombol */
.prev-btn, .next-btn {
position: absolute;
padding: 10px 20px;
font-size: 16px;
border: none;
border-radius: 5px;
cursor: pointer;
background: #333;
color: white;
z-index: 10;
}
.prev-btn {
top: 10px;
left: 10px;
}
.next-btn {
bottom: 10px;
right: 10px;
}
.prev-btn:disabled, .next-btn:disabled {
background: #aaa;
cursor: not-allowed;
}
</style>
</head>
<body>
<div class="book-container">
<div class="page" id="page1">Halaman 1</div>
<div class="page" id="page2">Halaman 2</div>
<div class="page" id="page3">Halaman 3</div>
<div class="page" id="page4">Halaman 4</div>
<div class="page" id="page5">Halaman 5</div>
<button class="prev-btn" id="prevBtn" disabled>⟵ Kembali</button>
<button class="next-btn" id="nextBtn">Lanjut ⟶</button>
</div>
<script>
const pages = document.querySelectorAll('.page');
let currentPage = 0;
const prevBtn = document.getElementById('prevBtn');
const nextBtn = document.getElementById('nextBtn');
function updateFlip(direction) {
if (direction === 'next' && currentPage < pages.length - 1) {
pages[currentPage].style.transform = 'rotateY(-180deg)';
currentPage++;
} else if (direction === 'prev' && currentPage > 0) {
currentPage--;
pages[currentPage].style.transform = 'rotateY(0deg)';
}
// Update button states
prevBtn.disabled = currentPage === 0;
nextBtn.disabled = currentPage === pages.length - 1;
}
prevBtn.addEventListener('click', () => updateFlip('prev'));
nextBtn.addEventListener('click', () => updateFlip('next'));
</script>
</body>
</html>

Tidak ada komentar:
Posting Komentar