click-only-reflesh-picture.html
· 1.1 KiB · HTML
Raw
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>局部刷新图片</title>
<style>
body {
display: flex;
justify-content: center;
align-items: center;
margin: 0;
height: 100vh;
background-color: #f4f4f9;
}
img {
max-width: 90%; /* 限制图片最大宽度为屏幕的 90% */
height: auto; /* 保持图片的宽高比 */
border: 2px solid #333;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
cursor: pointer; /* 鼠标悬停显示为手型 */
}
</style>
</head>
<body>
<img id="dynamicImage" src="https://birdteam.net/heisi.php" alt="动态图片" title="点击刷新图片">
<script>
const image = document.getElementById('dynamicImage');
image.addEventListener('click', () => {
image.src = `https://birdteam.net/heisi.php?timestamp=${new Date().getTime()}`; // 更新图片地址,这个时间戳的参数并不是api所需,而是为了防止缓存,而添加了个参数,使url不一样
});
</script>
</body>
</html>
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>局部刷新图片</title> |
7 | <style> |
8 | body { |
9 | display: flex; |
10 | justify-content: center; |
11 | align-items: center; |
12 | margin: 0; |
13 | height: 100vh; |
14 | background-color: #f4f4f9; |
15 | } |
16 | img { |
17 | max-width: 90%; /* 限制图片最大宽度为屏幕的 90% */ |
18 | height: auto; /* 保持图片的宽高比 */ |
19 | border: 2px solid #333; |
20 | box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2); |
21 | cursor: pointer; /* 鼠标悬停显示为手型 */ |
22 | } |
23 | </style> |
24 | </head> |
25 | <body> |
26 | <img id="dynamicImage" src="https://birdteam.net/heisi.php" alt="动态图片" title="点击刷新图片"> |
27 | |
28 | <script> |
29 | const image = document.getElementById('dynamicImage'); |
30 | |
31 | image.addEventListener('click', () => { |
32 | image.src = `https://birdteam.net/heisi.php?timestamp=${new Date().getTime()}`; // 更新图片地址,这个时间戳的参数并不是api所需,而是为了防止缓存,而添加了个参数,使url不一样 |
33 | }); |
34 | </script> |
35 | </body> |
36 | </html> |
37 |