翻页效果实现
This commit is contained in:
parent
6848fc1f44
commit
7de4f5517d
95
Web/翻页/css/main.css
Normal file
95
Web/翻页/css/main.css
Normal file
@ -0,0 +1,95 @@
|
|||||||
|
* {
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
box-sizing: border-box;
|
||||||
|
}
|
||||||
|
|
||||||
|
body {
|
||||||
|
font-family: 'Microsoft YaHei', sans-serif;
|
||||||
|
background-color: #f5f5f5;
|
||||||
|
}
|
||||||
|
|
||||||
|
.page {
|
||||||
|
width: 100%;
|
||||||
|
min-height: 100vh;
|
||||||
|
display: none;
|
||||||
|
padding: 40px;
|
||||||
|
background-color: #fff;
|
||||||
|
transition: all 0.3s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.page.active {
|
||||||
|
display: block;
|
||||||
|
animation: fadeIn 0.5s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.navigation {
|
||||||
|
position: fixed;
|
||||||
|
bottom: 30px;
|
||||||
|
left: 50%;
|
||||||
|
transform: translateX(-50%);
|
||||||
|
background-color: rgba(255, 255, 255, 0.9);
|
||||||
|
padding: 15px 25px;
|
||||||
|
border-radius: 50px;
|
||||||
|
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
|
||||||
|
}
|
||||||
|
|
||||||
|
.navigation button {
|
||||||
|
padding: 8px 20px;
|
||||||
|
margin: 0 10px;
|
||||||
|
border: none;
|
||||||
|
border-radius: 25px;
|
||||||
|
background-color: #4CAF50;
|
||||||
|
color: white;
|
||||||
|
cursor: pointer;
|
||||||
|
transition: all 0.3s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.navigation button:hover {
|
||||||
|
background-color: #45a049;
|
||||||
|
transform: translateY(-2px);
|
||||||
|
}
|
||||||
|
|
||||||
|
#pageIndicator {
|
||||||
|
margin: 0 15px;
|
||||||
|
font-size: 16px;
|
||||||
|
color: #333;
|
||||||
|
}
|
||||||
|
|
||||||
|
.content-container {
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
gap: 20px;
|
||||||
|
justify-content: center;
|
||||||
|
max-width: 1200px;
|
||||||
|
margin: 0 auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.content-item {
|
||||||
|
width: 280px;
|
||||||
|
height: 200px;
|
||||||
|
background-color: #ffffff;
|
||||||
|
border-radius: 15px;
|
||||||
|
padding: 20px;
|
||||||
|
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
|
||||||
|
transition: all 0.3s ease;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
text-align: center;
|
||||||
|
font-size: 18px;
|
||||||
|
color: #333;
|
||||||
|
}
|
||||||
|
|
||||||
|
.content-item:hover {
|
||||||
|
transform: translateY(-5px);
|
||||||
|
box-shadow: 0 6px 12px rgba(0, 0, 0, 0.15);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 添加页面标题 */
|
||||||
|
.page-title {
|
||||||
|
text-align: center;
|
||||||
|
margin-bottom: 30px;
|
||||||
|
color: #333;
|
||||||
|
font-size: 24px;
|
||||||
|
}
|
21
Web/翻页/index.html
Normal file
21
Web/翻页/index.html
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>翻页效果</title>
|
||||||
|
<link rel="stylesheet" href="css/main.css">
|
||||||
|
<script src="js/main.js"></script>
|
||||||
|
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div id="pagesContainer"></div>
|
||||||
|
|
||||||
|
<div class="navigation">
|
||||||
|
<button onclick="prevPage()">上一页</button>
|
||||||
|
<span id="pageIndicator"></span>
|
||||||
|
<button onclick="nextPage()">下一页</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
70
Web/翻页/js/main.js
Normal file
70
Web/翻页/js/main.js
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
let currentPage = 1;
|
||||||
|
let totalPages = 0;
|
||||||
|
let itemsPerPage = 0;
|
||||||
|
|
||||||
|
window.onload = function() {
|
||||||
|
totalPages = parseInt(prompt("请输入要创建的页面数量:", "3"));
|
||||||
|
itemsPerPage = parseInt(prompt("请输入每页的栏目数:", "4"));
|
||||||
|
|
||||||
|
generatePages();
|
||||||
|
showPage(1);
|
||||||
|
updatePageIndicator();
|
||||||
|
}
|
||||||
|
|
||||||
|
function generatePages() {
|
||||||
|
const container = document.getElementById('pagesContainer');
|
||||||
|
|
||||||
|
for(let i = 0; i < totalPages; i++) {
|
||||||
|
const page = document.createElement('div');
|
||||||
|
page.className = 'page';
|
||||||
|
page.id = `page${i+1}`;
|
||||||
|
|
||||||
|
// 添加页面标题
|
||||||
|
const title = document.createElement('h2');
|
||||||
|
title.className = 'page-title';
|
||||||
|
title.innerHTML = `第 ${i+1} 页`;
|
||||||
|
page.appendChild(title);
|
||||||
|
|
||||||
|
const contentContainer = document.createElement('div');
|
||||||
|
contentContainer.className = 'content-container';
|
||||||
|
|
||||||
|
for(let j = 0; j < itemsPerPage; j++) {
|
||||||
|
const item = document.createElement('div');
|
||||||
|
item.className = 'content-item';
|
||||||
|
item.innerHTML = `内容 ${j+1}`;
|
||||||
|
contentContainer.appendChild(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
page.appendChild(contentContainer);
|
||||||
|
container.appendChild(page);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function showPage(pageNum) {
|
||||||
|
document.querySelectorAll('.page').forEach(page => {
|
||||||
|
page.classList.remove('active');
|
||||||
|
});
|
||||||
|
|
||||||
|
document.getElementById(`page${pageNum}`).classList.add('active');
|
||||||
|
}
|
||||||
|
|
||||||
|
function nextPage() {
|
||||||
|
if(currentPage < totalPages) {
|
||||||
|
currentPage++;
|
||||||
|
showPage(currentPage);
|
||||||
|
updatePageIndicator();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function prevPage() {
|
||||||
|
if(currentPage > 1) {
|
||||||
|
currentPage--;
|
||||||
|
showPage(currentPage);
|
||||||
|
updatePageIndicator();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function updatePageIndicator() {
|
||||||
|
document.getElementById('pageIndicator').textContent =
|
||||||
|
`${currentPage} / ${totalPages}`;
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user