<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>3D翻页电子书特效</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'Arial', sans-serif;
background: #f5f5f5;
display: flex;
flex-direction: column;
align-items: center;
min-height: 100vh;
padding: 20px;
}
h1 {
margin: 20px 0;
color: #333;
}
.book-container {
perspective: 1500px;
width: 90%;
max-width: 800px;
height: 500px;
position: relative;
margin: 20px auto;
}
.book {
width: 100%;
height: 100%;
position: relative;
transform-style: preserve-3d;
transition: transform 1s;
}
.page {
position: absolute;
width: 50%;
height: 100%;
top: 0;
background: white;
box-shadow: 0 0 10px rgba(0,0,0,0.2);
padding: 20px;
overflow: hidden;
backface-visibility: hidden;
transform-origin: left center;
transition: transform 1s;
}
.page-content {
height: 100%;
overflow-y: auto;
}
.page-cover {
background: linear-gradient(135deg, #3498db, #2c3e50);
color: white;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
text-align: center;
}
.page-cover h2 {
font-size: 2.5rem;
margin-bottom: 20px;
}
.page-cover p {
font-size: 1.2rem;
margin-bottom: 30px;
}
.page-back-cover {
background: linear-gradient(135deg, #2c3e50, #3498db);
color: white;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
text-align: center;
}
.page-left {
left: 0;
z-index: 10;
}
.page-right {
left: 50%;
z-index: 1;
}
.page-flipped {
transform: rotateY(-180deg);
z-index: 0;
}
.controls {
margin: 20px 0;
display: flex;
gap: 20px;
}
button {
padding: 10px 20px;
background: #3498db;
color: white;
border: none;
border-radius: 5px;
cursor: pointer;
font-size: 1rem;
transition: background 0.3s;
}
button:hover {
background: #2980b9;
}
button:disabled {
background: #95a5a6;
cursor: not-allowed;
}
.website-link {
margin-top: 30px;
color: #3498db;
text-decoration: none;
font-size: 1.2rem;
}
.website-link:hover {
text-decoration: underline;
}
</style>
</head>
<body>
<h1>3D翻页电子书特效</h1>
<div class="book-container">
<div class="book" id="book">
<!-- 封面 -->
<div class="page page-left page-cover">
<div class="page-content">
<h2>HTML5 3D电子书</h2>
<p>使用CSS3和JavaScript实现</p>
<p>点击下方按钮翻页</p>
</div>
</div>
<!-- 第1页 -->
<div class="page page-right">
<div class="page-content">
<h3>第一页</h3>
<p>这是电子书的第一页内容。HTML5提供了强大的3D变换功能,结合CSS3的transform属性,我们可以创建逼真的3D翻页效果。</p>
<p>本示例使用了transform-style: preserve-3d来保持3D空间,以及transform-origin设置旋转中心点。</p>
</div>
</div>
<!-- 第2页 -->
<div class="page page-right">
<div class="page-content">
<h3>第二页</h3>
<p>JavaScript用于控制翻页动画。当点击"下一页"按钮时,当前页面会绕左侧边缘旋转180度,同时下一页面会从右侧翻转过来。</p>
<p>backface-visibility属性确保页面背面在旋转时不可见,从而创建更真实的翻页效果。</p>
</div>
</div>
<!-- 第3页 -->
<div class="page page-right">
<div class="page-content">
<h3>第三页</h3>
<p>电子书效果可以应用于多种场景:</p>
<ul>
<li>在线杂志和期刊</li>
<li>产品展示</li>
<li>交互式教程</li>
<li>数字相册</li>
</ul>
<p>通过调整CSS可以自定义书籍的外观和动画效果。</p>
</div>
</div>
<!-- 封底 -->
<div class="page page-right page-back-cover">
<div class="page-content">
<h3>感谢阅读</h3>
<p>这本3D电子书演示到此结束。</p>
<p>希望这个示例对您有所帮助!</p>
</div>
</div>
</div>
</div>
<div class="controls">
<button id="prevBtn" disabled>上一页</button>
<button id="nextBtn">下一页</button>
</div>
<script>
document.addEventListener('DOMContentLoaded', function() {
const book = document.getElementById('book');
const prevBtn = document.getElementById('prevBtn');
const nextBtn = document.getElementById('nextBtn');
const pages = document.querySelectorAll('.page');
let currentPage = 0;
const totalPages = pages.length - 1;
// 初始化页面位置
function initPages() {
for (let i = 0; i < pages.length; i++) {
if (i <= 1) {
// 封面和第一页初始可见
pages[i].style.transform = 'rotateY(0deg)';
pages[i].style.zIndex = pages.length - i;
} else {
// 其他页面初始隐藏
pages[i].style.transform = 'rotateY(-180deg)';
pages[i].style.zIndex = 0;
}
}
}
initPages();
// 翻到下一页
function nextPage() {
if (currentPage >= totalPages - 1) return;
currentPage++;
updateButtons();
// 当前页面翻过去
pages[currentPage].classList.add('page-flipped');
pages[currentPage].style.zIndex = pages.length - currentPage;
// 下一页面翻过来
if (currentPage + 1 <= totalPages) {
pages[currentPage + 1].style.transform = 'rotateY(0deg)';
pages[currentPage + 1].style.zIndex = pages.length - currentPage - 1;
}
}
// 翻到上一页
function prevPage() {
if (currentPage <= 0) return;
// 当前页面翻回来
pages[currentPage].classList.remove('page-flipped');
pages[currentPage].style.zIndex = pages.length - currentPage + 1;
// 下一页面翻回去
if (currentPage + 1 <= totalPages) {
pages[currentPage + 1].style.transform = 'rotateY(-180deg)';
pages[currentPage + 1].style.zIndex = 0;
}
currentPage--;
updateButtons();
}
// 更新按钮状态
function updateButtons() {
prevBtn.disabled = currentPage <= 0;
nextBtn.disabled = currentPage >= totalPages - 1;
}
// 事件监听
nextBtn.addEventListener('click', nextPage);
prevBtn.addEventListener('click', prevPage);
// 添加键盘控制
document.addEventListener('keydown', function(e) {
if (e.key === 'ArrowRight') {
nextPage();
} else if (e.key === 'ArrowLeft') {
prevPage();
}
});
});
</script>
</body>
</html>
3D翻页电子书特效
于 2025-05-19 16:05:13 首次发布
1011

被折叠的 条评论
为什么被折叠?



