注意从官方下载最新版,我之前直接用cdn不是最新版的,导致有些问题
html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>翻页</title>
<style>
body {
margin: 0;
padding: 0;
}
.img {
width: 100%;
height: 100%;
margin: 0 auto;
font-size: 30px;
background: #eeeeee;
}
#prev,
#next {
position: fixed;
top: 50%;
z-index: 100;
}
#prev {
left: 0;
}
#next {
right: 0;
}
#flipbook .turn-page {
background-color: #ccc;
}
</style>
<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.4/jquery.min.js"></script>
<script src="./turn.js"></script>
</head>
<body>
<div id="flipbook">
<div class="img">1
</div>
<div class="img">2
</div>
<div class="img">3
</div>
<div class="img">4
</div>
<div class="img">5
</div>
<div class="img">6
</div>
<div class="img">7
</div>
<div class="img">8
</div>
<div class="img">9
</div>
<div class="img">10
</div>
</div>
<div id="prev">上一页</div>
<div id="next">下一页</div>
<script type="text/javascript">
$('#flipbook').turn({
width: $(window).width(),
height: $(window).height(),
acceleration: true, // 移动端硬件加速
autoCenter: true, // 自动居中
display: 'single',
when: {
turned(event, page, view) {
if (page !== $(this).turn('pages')) {
// 卷角
$(this).turn('peel', 'br');
}
}
}
});
$('#prev').bind('click', function () {
$('#flipbook').turn('previous');
});
$('#next').bind('click', function () {
$('#flipbook').turn('next');
});
</script>
</body>
</html>