-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
211 lines (184 loc) · 6.97 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>日本の歴史タイムラインギャラリー</title>
<style>
@import url('https://fonts.googleapis.com/css2?family=Noto+Serif+JP:wght@400;700&display=swap');
body {
font-family: 'Noto Serif JP', serif;
margin: 0;
padding: 0;
background-color: #fdf6e3;
color: #333;
}
.slider-container {
display: flex; /* 確保滑塊橫向排列 */
width: 100%;
max-width: 1800px;
margin: 30px auto;
position: relative;
overflow-x: scroll; /* 允許水平滾動 */
overflow-y: hidden; /* 隱藏垂直滾動 */
scrollbar-width: none; /* Firefox 隱藏滾動條 */
border-radius: 12px;
box-shadow: 0 6px 16px rgba(0, 0, 0, 0.15);
background-color: #fefaf3;
cursor: grab; /* 手型指標 */
}
.slider-container::-webkit-scrollbar {
display: none; /* 隱藏 Safari 和 Chrome 的滾動條 */
}
.slider-container:active {
cursor: grabbing;
}
.slide {
flex: 0 0 100%; /* 每個滑塊佔據 100% 的寬度 */
height: 500px; /* 預設高度 */
display: flex;
justify-content: center;
align-items: center;
background-size: cover;
background-position: center;
}
@media (min-width: 768px) {
.slide {
height: 700px; /* 平板高度 */
}
}
@media (min-width: 1024px) {
.slide {
height: 850px; /* 桌面高度 */
}
}
.timeline {
display: flex;
justify-content: center;
flex-wrap: wrap;
margin: 20px 10px;
gap: 8px;
}
.timeline-button {
padding: 10px 15px;
border: none;
background-color: #88c0d0;
color: #fff;
font-size: 12px;
font-weight: 700;
cursor: pointer;
border-radius: 20px;
transition: background-color 0.3s ease, transform 0.2s;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}
.timeline-button:hover {
background-color: #81a1c1;
transform: translateY(-2px);
}
.timeline-button.active {
background-color: #5e81ac;
}
@media (min-width: 768px) {
.timeline-button {
font-size: 14px;
padding: 12px 20px;
}
}
footer {
margin-top: 30px;
text-align: center;
font-size: 12px;
color: #555;
}
@media (min-width: 768px) {
footer {
font-size: 14px;
}
}
</style>
</head>
<body>
<div class="slider-container">
<div class="slide" style="background-image: url('1.webp');"></div>
<div class="slide" style="background-image: url('2.webp');"></div>
<div class="slide" style="background-image: url('3.webp');"></div>
<div class="slide" style="background-image: url('4.webp');"></div>
<div class="slide" style="background-image: url('5.webp');"></div>
<div class="slide" style="background-image: url('6.webp');"></div>
<div class="slide" style="background-image: url('7.webp');"></div>
<div class="slide" style="background-image: url('8.webp');"></div>
<div class="slide" style="background-image: url('9.webp');"></div>
<div class="slide" style="background-image: url('10.webp');"></div>
</div>
<div class="timeline">
<button class="timeline-button" onclick="moveToSlide(0)">縄文時代</button>
<button class="timeline-button" onclick="moveToSlide(1)">弥生時代</button>
<button class="timeline-button" onclick="moveToSlide(2)">平安時代</button>
<button class="timeline-button" onclick="moveToSlide(3)">戦国時代</button>
<button class="timeline-button" onclick="moveToSlide(4)">江戸時代</button>
<button class="timeline-button" onclick="moveToSlide(5)">明治維新</button>
<button class="timeline-button" onclick="moveToSlide(6)">大正時代</button>
<button class="timeline-button" onclick="moveToSlide(7)">昭和時代</button>
<button class="timeline-button" onclick="moveToSlide(8)">平成時代</button>
<button class="timeline-button" onclick="moveToSlide(9)">令和時代</button>
</div>
<footer>
日本の歴史タイムラインギャラリー © 2025
</footer>
<script>
const sliderContainer = document.querySelector('.slider-container');
const buttons = document.querySelectorAll('.timeline-button');
let isDragging = false;
let startX;
let scrollLeft;
// 滑鼠拖曳功能
sliderContainer.addEventListener('mousedown', (e) => {
isDragging = true;
startX = e.pageX - sliderContainer.offsetLeft;
scrollLeft = sliderContainer.scrollLeft;
});
sliderContainer.addEventListener('mouseleave', () => {
isDragging = false;
});
sliderContainer.addEventListener('mouseup', () => {
isDragging = false;
});
sliderContainer.addEventListener('mousemove', (e) => {
if (!isDragging) return;
e.preventDefault();
const x = e.pageX - sliderContainer.offsetLeft;
const walk = (x - startX) * 1; // 調整拖曳速度
sliderContainer.scrollLeft = scrollLeft - walk;
});
// 觸控拖曳
sliderContainer.addEventListener('touchstart', (e) => {
isDragging = true;
startX = e.touches[0].pageX - sliderContainer.offsetLeft;
scrollLeft = sliderContainer.scrollLeft;
e.preventDefault(); // 阻止預設行為(例如頁面滾動)
});
sliderContainer.addEventListener('touchend', () => {
isDragging = false;
});
sliderContainer.addEventListener('touchmove', (e) => {
if (!isDragging) return;
const x = e.touches[0].pageX - sliderContainer.offsetLeft;
const walk = (x - startX) * 1; // 調整觸控滑動速度
sliderContainer.scrollLeft = scrollLeft - walk;
e.preventDefault(); // 阻止預設行為(例如頁面滾動)
});
// 按鈕點擊切換滑塊
function moveToSlide(index) {
const slideWidth = sliderContainer.offsetWidth;
sliderContainer.scrollTo({
left: index * slideWidth,
behavior: 'smooth',
});
buttons.forEach((btn) => btn.classList.remove('active'));
buttons[index].classList.add('active');
}
// 初始化按鈕狀態
moveToSlide(0);
</script>
</body>
</html>