📮实现头像按钮获取全部数据(未完成)

This commit is contained in:
柳神 2024-07-11 15:30:10 +08:00
parent 75942db125
commit 9dd43b1ac6
4 changed files with 140 additions and 25 deletions

View File

@ -9,6 +9,15 @@
<body> <body>
<div id="articles-container" class="articles-container"></div> <div id="articles-container" class="articles-container"></div>
<button id="load-more-btn">显示更多</button> <button id="load-more-btn">显示更多</button>
<!-- 模态框结构 -->
<div id="modal" class="modal">
<div class="modal-content">
<img id="modal-author-avatar" src="modal-author-avatar" alt="">
<a id="modal-author-name-link"></a>
<div id="modal-articles-container"></div>
</div>
</div>
<script src="./static/script.js"></script> <script src="./static/script.js"></script>
</body> </body>
</html> </html>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 951 B

View File

@ -7,6 +7,7 @@ document.addEventListener("DOMContentLoaded", function () {
fetch('./all.json') fetch('./all.json')
.then(response => response.json()) .then(response => response.json())
.then(data => { .then(data => {
allArticles = data.article_data;
const articles = data.article_data.slice(start, start + batchSize); const articles = data.article_data.slice(start, start + batchSize);
articles.forEach(article => { articles.forEach(article => {
const card = document.createElement('div'); const card = document.createElement('div');
@ -29,11 +30,12 @@ document.addEventListener("DOMContentLoaded", function () {
author.appendChild(document.createTextNode(article.author)); author.appendChild(document.createTextNode(article.author));
card.appendChild(author); card.appendChild(author);
author.onclick = () => {
showAuthorArticles(article.author, article.avatar, article.link);
};
const date = document.createElement('div'); const date = document.createElement('div');
date.className = 'card-date'; date.className = 'card-date';
const dateImg = document.createElement('img');
dateImg.src = './static/img/rili.png'; // 替换为实际的图标路径
date.appendChild(dateImg);
date.appendChild(document.createTextNode(article.created.substring(0, 10))); date.appendChild(document.createTextNode(article.created.substring(0, 10)));
card.appendChild(date); card.appendChild(date);
@ -54,9 +56,52 @@ document.addEventListener("DOMContentLoaded", function () {
}); });
} }
// 显示作者文章的函数
function showAuthorArticles(author, avatar, link) {
const modal = document.getElementById('modal');
const modalArticlesContainer = document.getElementById('modal-articles-container');
const modalAuthorAvatar = document.getElementById('modal-author-avatar');
const modalAuthorNameLink = document.getElementById('modal-author-name-link');
modalArticlesContainer.innerHTML = ''; // 清空之前的内容
modalAuthorAvatar.src = avatar;
modalAuthorNameLink.innerText = author;
modalAuthorNameLink.href = new URL(link).origin;
const authorArticles = allArticles.filter(article => article.author === author);
authorArticles.forEach(article => {
const articleDiv = document.createElement('div');
articleDiv.className = 'modal-article';
const title = document.createElement('a');
title.className = 'modal-article-title';
title.innerText = article.title;
title.href = article.link;
title.target = '_blank';
articleDiv.appendChild(title);
const date = document.createElement('div');
date.className = 'modal-article-date';
date.innerText = article.created.substring(0, 10);
articleDiv.appendChild(date);
modalArticlesContainer.appendChild(articleDiv);
});
modal.style.display = 'block';
}
// 初始加载 // 初始加载
loadMoreArticles(); loadMoreArticles();
// 加载更多按钮点击事件 // 加载更多按钮点击事件
document.getElementById('load-more-btn').addEventListener('click', loadMoreArticles); document.getElementById('load-more-btn').addEventListener('click', loadMoreArticles);
// 点击遮罩层关闭模态框
window.onclick = function(event) {
const modal = document.getElementById('modal');
if (event.target === modal) {
modal.style.display = 'none';
}
};
}); });

View File

@ -10,6 +10,72 @@ body {
min-height: 100vh; min-height: 100vh;
} }
/* 模态框样式 */
.modal {
display: none; /* 默认隐藏 */
position: absolute;
z-index: 1;
left: 0;
top: 0;
width: 100%;
height: 100%;
overflow: hidden;
backdrop-filter: blur(10px);
-webkit-backdrop-filter: blur(10px); /* 模糊背景 */
background-color: rgba(255, 255, 255, 0.5); /* 背景遮罩 */
}
.modal-content {
background-color: #fefefe;
margin: 50% auto;
padding: 20px;
border: 1px solid #888;
width: 320px;
max-width: 600px;
border-radius: 8px;
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}
@media screen and (max-width: 400px) {
.modal-content {
width: 80%;
}
}
#modal-author-avatar {
display: block;
margin: 0 auto 10px; /* 垂直方向上自动居中,底部留出间距 */
border-radius: 50%; /* 圆形图标 */
width: 80px;
height: 80px;
}
#modal-author-name-link {
display: block;
text-align: center;
font-size: 15px;
margin: 20px 0;
color: #007BFF;
text-decoration: none;
}
#modal-author-name-link:hover {
text-decoration: underline;
}
.modal-content hr {
margin: 20px 0;
}
#modal-articles-container {
border-top:#007BFF solid 1px;
margin-top: 30px;
padding-top: 30px;
}
/* 其他样式... */
.articles-container { .articles-container {
display: grid; display: grid;
grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
@ -22,7 +88,7 @@ body {
font-size: 15px; font-size: 15px;
background-color: white; background-color: white;
margin-top: 20px; margin-top: 20px;
width: 50%; width: 200px;
border-radius: 20px; border-radius: 20px;
padding: 3px; padding: 3px;
border:#b5b5b5 solid 1px; border:#b5b5b5 solid 1px;
@ -31,7 +97,7 @@ body {
#load-more-btn:hover { #load-more-btn:hover {
background-color: #0088ff; background-color: #0088ff;
width: 52%; width: 300px;
color: white; color: white;
} }
@ -40,7 +106,7 @@ body {
background-color: white; background-color: white;
border-radius: 10px; border-radius: 10px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1); box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
padding: 15px; padding: 10px;
position: relative; position: relative;
overflow: hidden; overflow: hidden;
display: flex; display: flex;
@ -51,6 +117,7 @@ body {
.card-title { .card-title {
font-size: 17px; font-size: 17px;
cursor: pointer;
margin-bottom: 10px; margin-bottom: 10px;
line-height: 1.5; line-height: 1.5;
max-height: 4.5em; /* 三行高度 */ max-height: 4.5em; /* 三行高度 */
@ -72,20 +139,20 @@ body {
.card-date { .card-date {
display: inline-block; display: inline-block;
font-size: 12px; font-size: 12px;
color: #888; color: #313131;
background-color: white; /* 白色背景 */
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1); /* 阴影 */
border-radius: 15px; /* 圆角 */
padding: 5px; /* 内边距 */ padding: 5px; /* 内边距 */
transition: box-shadow 0.2s; /* 过渡效果 */ transition: box-shadow 0.2s; /* 过渡效果 */
} }
.card-author:hover, .card-author:hover {
.card-date:hover {
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2); /* 鼠标悬停时加深阴影 */ box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2); /* 鼠标悬停时加深阴影 */
} }
.card-author { .card-author {
cursor: pointer;
background-color: white; /* 白色背景 */
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1); /* 阴影 */
border-radius: 15px; /* 圆角 */
display: flex; display: flex;
padding-right: 10px; padding-right: 10px;
width: fit-content; width: fit-content;
@ -102,26 +169,20 @@ body {
.card-date { .card-date {
position: absolute; position: absolute;
z-index: 1; z-index: 1;
bottom: 15px; bottom: 10px;
right: 15px; cursor: default;
right: 10px;
display: flex; display: flex;
align-items: center; align-items: center;
} }
.card-date img {
width: 15px;
height: 15px;
border-radius: 20%;
margin-right: 5px;
}
.card-bg { .card-bg {
z-index: 0; z-index: 0;
border-radius: 50%; border-radius: 50%;
position: absolute; position: absolute;
bottom: -30px; bottom: -15px;
right: -30px; right: -14px;
width: 150px; width: 120px;
height: 150px; height: 120px;
opacity: 0.1; opacity: 0.1;
} }