Skip to content

Commit 4e7c8bd

Browse files
committed
AZ,CA,NY
1 parent d4fd3ef commit 4e7c8bd

File tree

9 files changed

+13847
-2
lines changed

9 files changed

+13847
-2
lines changed

usa_map/AZ/index.html

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<title>Simple HTML Page</title>
7+
<style>
8+
body {
9+
font-family: Arial, sans-serif;
10+
text-align: center;
11+
margin: 50px;
12+
}
13+
h1 {
14+
color: #4CAF50;
15+
}
16+
p {
17+
font-size: 18px;
18+
color: #555;
19+
}
20+
#svgContainer {
21+
margin: 20px auto;
22+
display: inline-block;
23+
width: 100%;
24+
max-width: auto;
25+
}
26+
.map-container {
27+
display: flex;
28+
gap: 20px;
29+
}
30+
#usaMap {
31+
width: 60%; /* 增加宽度占比 */
32+
height: 80vh; /* 使用视口高度单位 */
33+
min-height: 500px; /* 设置最小高度 */
34+
border: 1px solid #ddd;
35+
}
36+
37+
#stateInfo {
38+
padding: 15px;
39+
border: 1px solid #ddd;
40+
border-radius: 5px;
41+
background-color: #fff;
42+
display: none;
43+
width: 200px;
44+
height: fit-content;
45+
}
46+
</style>
47+
</head>
48+
<body>
49+
<h1>Welcome to Arizona</h1>
50+
<p>This is the Arizona map:</p>
51+
52+
<!-- 嵌入外部 SVG 文件 -->
53+
<div class="map-container">
54+
<object id="usaMap" data="usa_az.svg" type="image/svg+xml" style="width: 60%; max-width: auto; height: auto; border: 1px solid #ddd;"></object>
55+
<div id="stateInfo"></div>
56+
</div>
57+
58+
<script>
59+
// 定义特定的州 ID 列表
60+
// const targetStates = ["AL", "AK", "AZ", "AR", "CA", "CO", "CT", "DE", "FL", "GA", "HI", "ID", "IL", "IN", "IA", "KS", "KY", "LA", "ME", "MD", "MA", "MI", "MN", "MS", "MO", "MT", "NE", "NV", "NH", "NJ", "NM", "NY", "NC", "ND", "OH", "OK", "OR", "PA", "RI", "SC", "SD", "TN", "TX", "UT", "VT", "VA", "WA", "WV", "WI", "WY"]; // 替换为你需要的州 ID
61+
62+
// 添加鼠标交互
63+
const svgObject = document.getElementById('usaMap');
64+
svgObject.addEventListener('load', () => {
65+
const svgDoc = svgObject.contentDocument; // 获取嵌入的 SVG 文档
66+
const states = svgDoc.querySelectorAll('path'); // 假设地图中的州使用 <path> 标签
67+
68+
69+
// 遍历每个州,并添加交互
70+
states.forEach(state => {
71+
// if (targetStates.includes(state.id)) { // 只处理特定 ID 的州
72+
state.addEventListener('mouseover', () => {
73+
state.style.fill = '#FF0000'; // 鼠标悬停时高亮
74+
75+
// 显示州名
76+
const stateInfo = document.getElementById('stateInfo');
77+
stateInfo.style.display = 'block';
78+
stateInfo.innerHTML = `
79+
<h3>${state.id}</h3>
80+
<p>这里是关于 ${state.id} 的详细信息</p>
81+
`;
82+
});
83+
state.addEventListener('mouseout', () => {
84+
state.style.fill = '#cccccc'; // 恢复原样
85+
});
86+
state.addEventListener('click', () => {
87+
const targetUrl = `https://danielchen3.github.io/usa_map/${state.id}`; // 替换为你需要跳转的网址
88+
window.location.href = targetUrl; // 跳转到指定网页
89+
});
90+
//}
91+
});
92+
});
93+
</script>
94+
</body>
95+
</html>

usa_map/AZ/test.html

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<title>SVG Image Example</title>
7+
<style>
8+
.svg-image {
9+
width: 300px;
10+
height: 300px;
11+
}
12+
</style>
13+
</head>
14+
<body>
15+
16+
<h1>SVG Image Example</h1>
17+
18+
<!-- 导入SVG图片并调整大小 -->
19+
<object class="svg-image" type="image/svg+xml" data="usa-az.svg"></object>
20+
21+
</body>
22+
</html>

usa_map/AZ/usa_az.svg

Lines changed: 19 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)