style: 优化页面样式和布局,提升用户体验

This commit is contained in:
2025-07-10 23:50:19 +08:00
parent f2c51f45b6
commit d0f9e65ad1
6 changed files with 644 additions and 115 deletions

View File

@@ -1,7 +1,7 @@
import app_conf import app_conf
import db.util import db.util
import db.file, file import db.file, file
from flask import * from flask import Flask
from router.api_Img import api_Img_bp from router.api_Img import api_Img_bp
from router.page import page_bp from router.page import page_bp
@@ -28,6 +28,6 @@ if __name__ == "__main__":
app.run( app.run(
debug=conf.getboolean("server", "debug"), debug=conf.getboolean("server", "debug"),
host=conf.get("server", "host"), host=conf.get("server", "host"),
port=conf.get("server", "port"), port=int(conf.get("server", "port")),
threaded=conf.getboolean("server", "threaded"), threaded=conf.getboolean("server", "threaded"),
) )

View File

@@ -7,37 +7,55 @@
<link href="/static/css/bootstrap.min.css" rel="stylesheet"> <link href="/static/css/bootstrap.min.css" rel="stylesheet">
<title>ComiPy-详情页面</title> <title>ComiPy-详情页面</title>
<style> <style>
* {
box-sizing: border-box;
}
body { body {
font-family: Arial, sans-serif; font-family: 'Google Sans', 'Roboto', 'Helvetica Neue', Arial, sans-serif;
margin: 0; margin: 0;
padding: 0; padding: 0;
background-color: #f8f9fa;
min-height: 100vh;
color: #202124;
line-height: 1.6;
} }
.container { .container {
display: flex; max-width: 1200px;
flex-direction: column; margin: 0 auto;
align-items: center; padding: 24px 16px;
background-color: #ffffff;
border-radius: 8px;
margin-top: 16px;
margin-bottom: 16px;
box-shadow: 0 1px 3px rgba(60, 64, 67, 0.3);
} }
.header { .header {
display: flex; display: flex;
justify-content: space-between;
flex-direction: column; flex-direction: column;
width: 80%; gap: 24px;
margin-top: 20px; margin-bottom: 24px;
} }
@media (min-width: 600px) { @media (min-width: 600px) {
.header { .header {
flex-direction: row; flex-direction: row;
align-items: flex-start;
} }
} }
.movie-poster { .movie-poster {
flex: 1; flex: 1;
margin-right: 20px; max-width: 300px;
}
.movie-poster img {
width: 100%;
height: auto;
border-radius: 8px;
box-shadow: 0 1px 3px rgba(60, 64, 67, 0.3);
} }
.movie-details { .movie-details {
@@ -45,28 +63,109 @@
} }
.movie-details h1 { .movie-details h1 {
font-size: 24px; font-size: 1.75rem;
margin-bottom: 10px; font-weight: 400;
color: #1a73e8;
margin-bottom: 16px;
} }
.movie-details p { .movie-details p {
font-size: 16px; font-size: 14px;
margin-bottom: 10px; color: #5f6368;
margin-bottom: 12px;
}
.btn {
background: #1a73e8;
border: 1px solid #1a73e8;
color: #ffffff;
padding: 8px 16px;
border-radius: 4px;
font-weight: 500;
font-size: 14px;
text-decoration: none;
display: inline-block;
transition: all 0.2s ease;
cursor: pointer;
}
.btn:hover {
background: #1557b0;
border-color: #1557b0;
color: #ffffff;
text-decoration: none;
}
.btn-outline {
background: #ffffff;
border: 1px solid #dadce0;
color: #1a73e8;
}
.btn-outline:hover {
background: #f8f9fa;
border-color: #1a73e8;
color: #1a73e8;
} }
.comments-section { .comments-section {
width: 80%; margin-top: 32px;
margin-top: 20px; }
.comments-section h2 {
color: #1a73e8;
font-weight: 400;
font-size: 1.25rem;
margin-bottom: 16px;
} }
.comment { .comment {
border: 1px solid #ccc; background: #f8f9fa;
padding: 10px; border: 1px solid #dadce0;
margin-bottom: 10px; border-radius: 8px;
padding: 16px;
margin-bottom: 12px;
} }
.comment p { .comment p {
margin: 0; margin: 0;
color: #202124;
}
.comment-meta {
font-size: 12px;
color: #5f6368;
margin-top: 8px;
}
.form-control {
border: 1px solid #dadce0;
border-radius: 4px;
padding: 12px;
font-family: inherit;
width: 100%;
margin-bottom: 12px;
}
.form-control:focus {
outline: none;
border-color: #1a73e8;
box-shadow: 0 0 0 2px rgba(26, 115, 232, 0.2);
}
.modal-content {
border-radius: 8px;
border: none;
box-shadow: 0 4px 8px rgba(60, 64, 67, 0.3);
}
.modal-header {
border-bottom: 1px solid #dadce0;
}
.modal-title {
color: #1a73e8;
font-weight: 400;
} }
</style> </style>
</head> </head>

View File

@@ -5,50 +5,84 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>ComiPy-登录</title> <title>ComiPy-登录</title>
<style> <style>
* {
box-sizing: border-box;
}
body { body {
font-family: Arial, sans-serif; font-family: 'Google Sans', 'Roboto', 'Helvetica Neue', Arial, sans-serif;
background-color: #f0f0f0; background-color: #f8f9fa;
display: flex; display: flex;
justify-content: center; justify-content: center;
align-items: center; align-items: center;
height: 100vh; height: 100vh;
margin: 0; margin: 0;
color: #202124;
line-height: 1.6;
} }
.container { .container {
background-color: #fff; background-color: #ffffff;
padding: 20px; padding: 32px;
border-radius: 5px; border-radius: 8px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); box-shadow: 0 1px 3px rgba(60, 64, 67, 0.3);
width: 100%;
max-width: 400px;
}
h1 {
text-align: center;
color: #1a73e8;
font-weight: 400;
margin-bottom: 24px;
} }
.form-group { .form-group {
margin-bottom: 15px; margin-bottom: 16px;
} }
.form-group label { .form-group label {
display: block; display: block;
margin-bottom: 5px; margin-bottom: 8px;
color: #202124;
font-weight: 500;
font-size: 14px;
} }
.form-group input { .form-group input {
width: 100%; width: 100%;
padding: 10px; padding: 12px;
border: 1px solid #ddd; border: 1px solid #dadce0;
border-radius: 3px; border-radius: 4px;
box-sizing: border-box; font-family: inherit;
font-size: 14px;
}
.form-group input:focus {
outline: none;
border-color: #1a73e8;
box-shadow: 0 0 0 2px rgba(26, 115, 232, 0.2);
} }
.form-group button { .form-group button {
width: 100%; width: 100%;
padding: 10px; padding: 12px;
background-color: #5cb85c; background: #1a73e8;
border: none; border: 1px solid #1a73e8;
border-radius: 3px; border-radius: 4px;
color: white; color: #ffffff;
cursor: pointer; cursor: pointer;
font-weight: 500;
font-size: 14px;
transition: all 0.2s ease;
} }
.form-group button:hover {
background: #1557b0;
border-color: #1557b0;
}
</style>
.form-group button:hover { .form-group button:hover {
background-color: #4cae4c; background-color: #4cae4c;
} }

View File

@@ -7,26 +7,38 @@
<link href="/static/css/bootstrap.min.css" rel="stylesheet"> <link href="/static/css/bootstrap.min.css" rel="stylesheet">
<title>ComiPy-概览</title> <title>ComiPy-概览</title>
<style> <style>
* {
box-sizing: border-box;
}
body { body {
font-family: Arial, sans-serif; font-family: 'Google Sans', 'Roboto', 'Helvetica Neue', Arial, sans-serif;
margin: 0; margin: 0;
padding: 20px; padding: 0;
background-color: #f0f0f0; background-color: #f8f9fa;
min-height: 100vh;
color: #202124;
line-height: 1.6;
}
.container {
max-width: 1400px;
margin: 0 auto;
padding: 24px 16px;
} }
#gallery { #gallery {
display: grid; display: grid;
grid-template-columns: repeat(2, 1fr); grid-template-columns: repeat(2, 1fr);
grid-gap: 20px; gap: 16px;
font-size: small; font-size: 14px;
} }
/* 当屏幕宽度大于600px时调整列数和列的宽度 */ /* 当屏幕宽度大于600px时调整列数和列的宽度 */
@media (min-width: 600px) { @media (min-width: 600px) {
#gallery { #gallery {
grid-template-columns: repeat(3, 1fr); grid-template-columns: repeat(3, 1fr);
font-size: medium; font-size: 15px;
/* 两列布局 */
} }
} }
@@ -34,20 +46,57 @@
@media (min-width: 900px) { @media (min-width: 900px) {
#gallery { #gallery {
grid-template-columns: repeat(5, 1fr); grid-template-columns: repeat(5, 1fr);
font-size: large; font-size: 16px;
/* 三列布局 */
} }
} }
.gallery-item {
background: #ffffff;
border-radius: 8px;
overflow: hidden;
box-shadow: 0 1px 3px rgba(60, 64, 67, 0.3);
transition: box-shadow 0.2s ease;
cursor: pointer;
}
.gallery-item:hover {
box-shadow: 0 4px 8px rgba(60, 64, 67, 0.3);
}
.gallery-item img {
width: 100%;
height: 200px;
object-fit: cover;
border-radius: 8px 8px 0 0;
}
.gallery-item-content {
padding: 12px;
}
.gallery-item h3 {
margin: 0 0 8px 0;
font-size: 1em;
font-weight: 500;
color: #1a73e8;
text-decoration: none;
}
.gallery-item p {
margin: 0;
color: #5f6368;
font-size: 0.875em;
}
#global-blur { #global-blur {
background-color: rgba(255, 255, 255, 0.5); background-color: rgba(255, 255, 255, 0.95);
position: fixed; position: fixed;
top: 0; top: 0;
left: 0; left: 0;
width: 100%; width: 100%;
height: 100%; height: 100%;
backdrop-filter: blur(10px); backdrop-filter: blur(8px);
-webkit-backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(8px);
/* 模糊度可以根据需要调整 */ /* 模糊度可以根据需要调整 */
transition: display; transition: display;
z-index: 10; z-index: 10;
@@ -77,20 +126,22 @@
</div> </div>
</div> </div>
<hr /> <hr />
<div class="container">
<div id="gallery"> <div id="gallery">
{% for item in list %} {% for item in list %}
<div class="card"> <div class="gallery-item" onclick="linkjump('{{ item[1] }}')">
{% if item[4] > aftertime %} {% if item[4] > aftertime %}
<span class="position-absolute top-0 start-100 translate-middle badge rounded-pill bg-danger">New</span> <span class="position-absolute top-0 start-100 translate-middle badge rounded-pill bg-danger">New</span>
{% endif %} {% endif %}
<img src="/api/img/{{ item[1] }}/0?mini=yes" class="img-thumbnail card-img-top" <img src="/api/img/{{ item[1] }}/0?mini=yes" alt="{{ item[2] }}" />
onclick="linkjump('{{ item[1] }}')" /> <div class="gallery-item-content">
<div class="card-body"> <h3>{{ item[2] }}</h3>
<p class="card-text">{{ item[2] }}</p> <p>点击查看详情</p>
</div> </div>
</div> </div>
{% endfor %} {% endfor %}
</div> </div>
</div>
<hr /> <hr />
<div style=display:flex;justify-content:center;align-items:center;> <div style=display:flex;justify-content:center;align-items:center;>
<ul class="pagination"> <ul class="pagination">

View File

@@ -9,11 +9,84 @@
<!-- Bootstrap CSS --> <!-- Bootstrap CSS -->
<link href="/static/css/bootstrap.min.css" rel="stylesheet"> <link href="/static/css/bootstrap.min.css" rel="stylesheet">
<style> <style>
/* Custom styles */ * {
box-sizing: border-box;
}
body {
font-family: 'Google Sans', 'Roboto', 'Helvetica Neue', Arial, sans-serif;
margin: 0;
padding: 0;
background-color: #f8f9fa;
min-height: 100vh;
color: #202124;
line-height: 1.6;
}
.container {
max-width: 600px;
margin: 0 auto;
padding: 24px 16px;
background-color: #ffffff;
border-radius: 8px;
margin-top: 40px;
box-shadow: 0 1px 3px rgba(60, 64, 67, 0.3);
}
h2 {
color: #1a73e8;
font-weight: 400;
margin-bottom: 24px;
text-align: center;
}
.form-control {
border: 1px solid #dadce0;
border-radius: 4px;
padding: 12px;
font-family: inherit;
}
.form-control:focus {
outline: none;
border-color: #1a73e8;
box-shadow: 0 0 0 2px rgba(26, 115, 232, 0.2);
}
.btn-primary {
background: #1a73e8;
border: 1px solid #1a73e8;
color: #ffffff;
padding: 12px 24px;
border-radius: 4px;
font-weight: 500;
transition: all 0.2s ease;
cursor: pointer;
}
.btn-primary:hover {
background: #1557b0;
border-color: #1557b0;
}
.progress {
background-color: #f1f3f4;
border-radius: 4px;
overflow: hidden;
margin-top: 16px;
}
#progress_bar { #progress_bar {
background-color: #1a73e8;
height: 8px;
width: 0; width: 0;
background-color: #64B587; transition: width 0.3s ease;
height: 20px; }
#loading {
margin-top: 12px;
color: #5f6368;
font-size: 14px;
} }
</style> </style>
</head> </head>

View File

@@ -6,82 +6,229 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>ComiPy-漫画详情页</title> <title>ComiPy-漫画详情页</title>
<style> <style>
* {
box-sizing: border-box;
}
body { body {
font-family: Arial, sans-serif; font-family: 'Google Sans', 'Roboto', 'Helvetica Neue', Arial, sans-serif;
margin: 0; margin: 0;
padding: 20px; padding: 0;
background-color: #f0f0f0; background-color: #f8f9fa;
min-height: 100vh;
color: #202124;
line-height: 1.6;
}
.header {
background: #ffffff;
padding: 12px 20px;
text-align: center;
box-shadow: 0 1px 3px rgba(60, 64, 67, 0.3);
position: fixed;
top: 0;
left: 0;
right: 0;
z-index: 100;
border-bottom: 1px solid #dadce0;
transform: translateY(0);
transition: transform 0.3s ease-in-out;
}
.header.hidden {
transform: translateY(-100%);
}
.header h1 {
display: none;
}
.page-info {
font-size: 0.8rem;
color: #5f6368;
margin-bottom: 8px;
font-weight: 400;
}
.container {
max-width: 1200px;
margin: 0 auto;
padding: 24px 16px;
background-color: #ffffff;
border-radius: 8px;
margin-top: 80px;
margin-bottom: 16px;
box-shadow: 0 1px 3px rgba(60, 64, 67, 0.3);
} }
#comic-container { #comic-container {
display: flex; display: flex;
flex-direction: column; flex-direction: column;
align-items: center; align-items: center;
gap: 16px;
margin-bottom: 32px;
} }
.comic-image { .comic-image {
max-width: 100%; max-width: 100%;
width: auto;
height: auto; height: auto;
margin-bottom: 20px; border-radius: 8px;
box-shadow: 0 1px 3px rgba(60, 64, 67, 0.3);
transition: box-shadow 0.3s ease;
background: #fff;
overflow: hidden;
}
.comic-image:hover {
box-shadow: 0 4px 8px rgba(60, 64, 67, 0.3);
} }
img { img {
display: block; display: block;
width: 100%; width: 100%;
min-height: 200px; min-height: 200px;
margin-top: 10px; border-radius: 4px;
background: linear-gradient(45deg, #f1f3f4 25%, transparent 25%, transparent 75%, #f1f3f4 75%),
linear-gradient(45deg, #f1f3f4 25%, transparent 25%, transparent 75%, #f1f3f4 75%);
background-size: 20px 20px;
background-position: 0 0, 10px 10px;
} }
#pagination { .pagination-container {
display: flex; display: flex;
flex-wrap: wrap; flex-wrap: wrap;
justify-content: center; justify-content: center;
align-items: center; align-items: center;
margin-top: 20px; gap: 8px;
margin: 16px 0;
} }
.page-button { .page-button {
padding: 10px 15px; padding: 8px 16px;
margin: 5px; background: #ffffff;
background-color: #007bff; color: #1a73e8;
color: white; border: 1px solid #dadce0;
border: none;
cursor: pointer; cursor: pointer;
border-radius: 5px; border-radius: 4px;
font-weight: 500;
font-size: 14px;
transition: all 0.2s ease;
min-width: 36px;
font-family: inherit;
}
.page-button:hover:not(:disabled) {
box-shadow: 0 1px 3px rgba(60, 64, 67, 0.3);
border-color: #1a73e8;
}
.page-button:active:not(:disabled) {
background: #f8f9fa;
} }
.page-button:disabled { .page-button:disabled {
background-color: #cccccc; background: #1a73e8;
} color: #ffffff;
border-color: #1a73e8;
.ellipsis {
padding: 10px 15px;
margin: 0 5px;
background-color: transparent;
border: none;
cursor: default; cursor: default;
} }
.page-button.nav-button {
background: #1a73e8;
color: #ffffff;
border-color: #1a73e8;
padding: 8px 24px;
font-size: 14px;
}
.page-button.nav-button:hover:not(:disabled) {
background: #1557b0;
box-shadow: 0 1px 3px rgba(60, 64, 67, 0.3);
}
.page-button:disabled.nav-button {
background: #dadce0;
color: #80868b;
border-color: #dadce0;
}
.ellipsis {
padding: 8px 16px;
margin: 0;
background: transparent;
border: none;
cursor: default;
color: #5f6368;
font-weight: 400;
}
.loading-placeholder {
background: linear-gradient(90deg, #f1f3f4 25%, #e8eaed 50%, #f1f3f4 75%);
background-size: 200% 100%;
animation: loading 1.5s infinite;
border-radius: 4px;
}
@keyframes loading {
0% { background-position: 200% 0; }
100% { background-position: -200% 0; }
}
#global-blur { #global-blur {
background-color: rgba(255, 255, 255, 0.8); background-color: rgba(255, 255, 255, 0.95);
position: fixed; position: fixed;
top: 0; top: 0;
left: 0; left: 0;
width: 100%; width: 100%;
height: 100%; height: 100%;
backdrop-filter: blur(12px); backdrop-filter: blur(8px);
-webkit-backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(8px);
transition: opacity 0.1s ease; transition: opacity 0.3s ease;
z-index: 1; z-index: 1000;
pointer-events: none; pointer-events: none;
opacity: 0; opacity: 0;
} }
@media (max-width: 768px) {
.header {
padding: 16px;
}
.header h1 {
font-size: 1.5rem;
}
.container {
margin: 8px;
padding: 16px 12px;
}
.page-button {
padding: 6px 12px;
font-size: 13px;
min-width: 32px;
}
.page-button.nav-button {
padding: 6px 16px;
font-size: 13px;
}
}
</style> </style>
</head> </head>
<body> <body>
<div class="header" id="header">
<div class="page-info" id="page-info">第 <span id="current-page-display">1</span> 页,共 <span id="total-pages-display">1</span> 页</div>
<div class="pagination-container" id="top-pagination"></div>
</div>
<div class="container">
<div id="comic-container"></div> <div id="comic-container"></div>
<div id="pagination"></div> <div class="pagination-container" id="bottom-pagination"></div>
</div>
<div id="global-blur" onclick="unshowGlobalBlur()"></div> <div id="global-blur" onclick="unshowGlobalBlur()"></div>
<script> <script>
document.addEventListener('DOMContentLoaded', function () { document.addEventListener('DOMContentLoaded', function () {
@@ -92,47 +239,142 @@
]; ];
const itemsPerPage = 25; // 每页显示的图片数量 const itemsPerPage = 25; // 每页显示的图片数量
let currentPage = 1; let currentPage = 1;
const totalPages = Math.ceil(imgsData.length / itemsPerPage);
function renderPage(page) { function renderPage(page) {
const comicContainer = document.getElementById('comic-container'); const comicContainer = document.getElementById('comic-container');
comicContainer.innerHTML = ''; // 清空当前内容 comicContainer.innerHTML = ''; // 清空当前内容
// 显示加载动画
showLoadingPlaceholders();
const start = (page - 1) * itemsPerPage; const start = (page - 1) * itemsPerPage;
const end = start + itemsPerPage; const end = start + itemsPerPage;
const pageItems = imgsData.slice(start, end); const pageItems = imgsData.slice(start, end);
pageItems.forEach(item => { // 清空加载动画并加载图片
setTimeout(() => {
comicContainer.innerHTML = '';
pageItems.forEach((item, index) => {
const img = document.createElement('img'); const img = document.createElement('img');
img.className = 'imgs comic-image'; img.className = 'imgs comic-image loading-placeholder';
img.setAttribute('data-src', item.src); img.setAttribute('data-src', item.src);
img.setAttribute('alt', item.alt); img.setAttribute('alt', item.alt);
img.onload = () => img.classList.remove('loading-placeholder');
comicContainer.appendChild(img); comicContainer.appendChild(img);
}); });
window.scrollTo(0, 0); // 滚动到页面顶部 window.scrollTo({ top: 0, behavior: 'smooth' }); // 平滑滚动到页面顶部
lazyLoad(); // 确保惰性加载生效 lazyLoad(); // 确保惰性加载生效
}, 300);
}
function showLoadingPlaceholders() {
const comicContainer = document.getElementById('comic-container');
comicContainer.innerHTML = '';
for (let i = 0; i < Math.min(itemsPerPage, 5); i++) {
const placeholder = document.createElement('div');
placeholder.className = 'comic-image loading-placeholder';
placeholder.style.height = '400px';
comicContainer.appendChild(placeholder);
}
}
function updatePageInfo() {
document.getElementById('current-page-display').textContent = currentPage;
document.getElementById('total-pages-display').textContent = totalPages;
} }
function renderPagination() { function renderPagination() {
const pagination = document.getElementById('pagination'); const topPagination = document.getElementById('top-pagination');
pagination.innerHTML = ''; // 清空当前内容 const bottomPagination = document.getElementById('bottom-pagination');
const totalPages = Math.ceil(imgsData.length / itemsPerPage); // 清空当前内容
topPagination.innerHTML = '';
bottomPagination.innerHTML = '';
if (totalPages <= 1) return; if (totalPages <= 1) return;
for (let i = 1; i <= totalPages; i++) { // 创建分页按钮
function createPaginationButtons(container) {
// 上一页按钮
const prevButton = document.createElement('button');
prevButton.className = 'page-button nav-button';
prevButton.innerHTML = '上一页';
prevButton.disabled = (currentPage === 1);
prevButton.addEventListener('click', () => {
if (currentPage > 1) {
currentPage--;
changePage();
}
});
container.appendChild(prevButton);
// 页码按钮
const startPage = Math.max(1, currentPage - 2);
const endPage = Math.min(totalPages, currentPage + 2);
// 第一页
if (startPage > 1) {
createPageButton(container, 1);
if (startPage > 2) {
const ellipsis = document.createElement('span');
ellipsis.className = 'ellipsis';
ellipsis.textContent = '...';
container.appendChild(ellipsis);
}
}
// 中间页码
for (let i = startPage; i <= endPage; i++) {
createPageButton(container, i);
}
// 最后一页
if (endPage < totalPages) {
if (endPage < totalPages - 1) {
const ellipsis = document.createElement('span');
ellipsis.className = 'ellipsis';
ellipsis.textContent = '...';
container.appendChild(ellipsis);
}
createPageButton(container, totalPages);
}
// 下一页按钮
const nextButton = document.createElement('button');
nextButton.className = 'page-button nav-button';
nextButton.innerHTML = '下一页';
nextButton.disabled = (currentPage === totalPages);
nextButton.addEventListener('click', () => {
if (currentPage < totalPages) {
currentPage++;
changePage();
}
});
container.appendChild(nextButton);
}
function createPageButton(container, pageNum) {
const button = document.createElement('button'); const button = document.createElement('button');
button.className = 'page-button'; button.className = 'page-button';
button.innerText = i; button.innerText = pageNum;
button.disabled = (i === currentPage); button.disabled = (pageNum === currentPage);
button.addEventListener('click', () => { button.addEventListener('click', () => {
currentPage = i; currentPage = pageNum;
renderPage(i); changePage();
renderPagination();
}); });
pagination.appendChild(button); container.appendChild(button);
} }
createPaginationButtons(topPagination);
createPaginationButtons(bottomPagination);
}
function changePage() {
renderPage(currentPage);
renderPagination();
updatePageInfo();
} }
function lazyLoad() { function lazyLoad() {
@@ -144,15 +386,43 @@
if (img.src) return; // 如果已经加载过了就跳过 if (img.src) return; // 如果已经加载过了就跳过
const imgTop = img.getBoundingClientRect().top + scrollY; const imgTop = img.getBoundingClientRect().top + scrollY;
if (windowHeight + scrollY > imgTop) { if (windowHeight + scrollY + 200 > imgTop) { // 提前200px开始加载
img.src = img.getAttribute('data-src'); img.src = img.getAttribute('data-src');
} }
}); });
} }
window.addEventListener('scroll', lazyLoad); // 键盘快捷键支持
document.addEventListener('keydown', (e) => {
if (e.key === 'ArrowLeft' && currentPage > 1) {
currentPage--;
changePage();
} else if (e.key === 'ArrowRight' && currentPage < totalPages) {
currentPage++;
changePage();
}
});
// 滚动隐藏顶栏功能
let lastScrollTop = 0;
const header = document.getElementById('header');
window.addEventListener('scroll', () => {
const scrollTop = window.pageYOffset || document.documentElement.scrollTop;
if (scrollTop > lastScrollTop && scrollTop > 100) {
// 向下滚动且滚动距离超过100px时隐藏
header.classList.add('hidden');
} else {
// 向上滚动时显示
header.classList.remove('hidden');
}
lastScrollTop = scrollTop <= 0 ? 0 : scrollTop; // 防止负数
lazyLoad();
});
window.addEventListener('resize', lazyLoad); window.addEventListener('resize', lazyLoad);
lazyLoad(); // 页面加载时初始化调用
const globalBlur = document.getElementById('global-blur'); const globalBlur = document.getElementById('global-blur');
@@ -166,6 +436,8 @@
} }
}); });
// 初始化页面
updatePageInfo();
renderPage(currentPage); renderPage(currentPage);
renderPagination(); renderPagination();
}); });