jQuery全屏垂直翻页是一种网页设计效果,通过使用jQuery库来实现页面内容的垂直滚动效果,使得用户可以像翻书一样浏览页面内容。这种效果通常用于展示多个页面或部分内容,每个页面或部分内容占据整个屏幕的高度。
以下是一个简单的jQuery全屏垂直翻页示例:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>jQuery Fullscreen Vertical Page Flip</title>
<style>
body, html {
margin: 0;
padding: 0;
height: 100%;
overflow: hidden;
}
.page {
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
font-size: 2em;
border-bottom: 1px solid #ccc;
}
</style>
</head>
<body>
<div class="page" id="page1">Page 1</div>
<div class="page" id="page2">Page 2</div>
<div class="page" id="page3">Page 3</div>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script>
$(document).ready(function() {
let currentPage = 1;
const totalPages = 3;
function scrollToPage(pageNumber) {
$('html, body').animate({
scrollTop: $(`.page:nth-child(${pageNumber})`).offset().top
}, 1000);
}
$('#page1').click(function() {
if (currentPage !== 1) {
scrollToPage(1);
currentPage = 1;
}
});
$('#page2').click(function() {
if (currentPage !== 2) {
scrollToPage(2);
currentPage = 2;
}
});
$('#page3').click(function() {
if (currentPage !== 3) {
scrollToPage(3);
currentPage = 3;
}
});
});
</script>
</body>
</html>
touchstart
、touchmove
和touchend
事件来处理触摸翻页逻辑。通过以上方法,可以有效地实现和优化jQuery全屏垂直翻页效果。
领取专属 10元无门槛券
手把手带您无忧上云