Skip to content

Commit 73b9ce0

Browse files
transport js
1 parent 05907ee commit 73b9ce0

2 files changed

Lines changed: 48 additions & 0 deletions

File tree

assets/js/allQuotes.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
2+
const quoteListElement = document.getElementById("quote-list");
3+
4+
fetch("../quotes.txt")
5+
.then(response => {
6+
if (!response.ok) throw new Error('Network response was not ok');
7+
return response.text();
8+
})
9+
.then(data => {
10+
quotes = data.split('\n').filter(quote => quote.trim() !== '');
11+
12+
// 将所有田语添加到田语列表
13+
quotes.forEach(quote => {
14+
const listItem = document.createElement("li");
15+
listItem.innerHTML = quote;
16+
quoteListElement.appendChild(listItem);
17+
});
18+
})
19+
.catch(error => {
20+
console.error('There was a problem with the fetch operation:', error);
21+
});

assets/js/script.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,3 +99,30 @@ document.addEventListener('visibilitychange', function () {
9999
document.title = '田语 | 朴实无华,意蕴悠长';
100100
}
101101
});
102+
103+
document.addEventListener("DOMContentLoaded", function () {
104+
105+
// 1. 选择所有需要动画的卡片
106+
const cards = document.querySelectorAll('.nav-card');
107+
108+
// 2. 创建一个观察者 (Intersection Observer)
109+
const observer = new IntersectionObserver((entries, observer) => {
110+
entries.forEach(entry => {
111+
// 如果卡片进入了视口 (即用户滑到了这里)
112+
if (entry.isIntersecting) {
113+
// 添加 .show 类,触发 CSS 动画
114+
entry.target.classList.add('show');
115+
116+
// 停止观察该元素 (保证动画只播放一次,往回滑不会再消失)
117+
observer.unobserve(entry.target);
118+
}
119+
});
120+
}, {
121+
threshold: 0.1 // 意思是:当卡片露出 10% 的时候就开始播放动画
122+
});
123+
124+
// 3. 让观察者开始观察每一个卡片
125+
cards.forEach(card => {
126+
observer.observe(card);
127+
});
128+
});

0 commit comments

Comments
 (0)