-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path新闻卡片 copy 5.html
96 lines (82 loc) · 2.18 KB
/
新闻卡片 copy 5.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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>News Card</title>
<style>
.card {
display: flex;
flex-direction: column;
align-items: center;
width: 480px;
height: 480px;
border: 1px solid #ccc;
border-radius: 15px;
padding: 20px;
background-image: linear-gradient(0deg, #a8edea 0%, #fed6e3 100%)
}
.title {
font-size: 24px;
font-weight: bold;
margin-bottom: 10px;
}
.content {
font-size: 16px;
margin-bottom: 20px;
}
#slider-container {
width: 100%;
height: 200px;
object-fit: cover;
margin-bottom: 20px;
border-radius: 15px;
}
.imagecss {
width: 100%;
height: 200px;
object-fit: cover;
margin-bottom: 20px;
border-radius: 15px;
}
</style>
</head>
<body>
<div class="card">
<img id="slider-image" src="">
<div class="card-body">
<h5 class="card-title"></h5>
<p class="card-text"></p>
</div>
</div>
<script>
let apidata;
let index = 0;
const titleElement = document.querySelectorAll('.card-title')[0];
const contentElement = document.querySelectorAll('.card-text')[0];
const imageElement = document.getElementById('slider-image');
function updateCard() {
// 设置标题和内容
titleElement.textContent = apidata.data.records[index].fields.title;
contentElement.textContent = apidata.data.records[index].fields.content;
// 设置图片
imageElement.src = apidata.data.records[index].fields.image[0].url;
// 增加索引并在必要时循环回开头
index = (index + 1) % apidata.data.records.length;
}
fetch('https://api.vika.cn/fusion/v1/datasheets/dst9mc5CYEGRRbfWxy/records?viewId=viwNzBnq8ZZwn&fieldKey=name', {
headers: {
'Authorization': 'Bearer uskdyEpUL0mOcLBBDrU5mbE'
}
})
.then(response => response.json())
.then(data => {
apidata = data;
console.log(apidata.data);
// 使用数据更新卡片元素
updateCard();
setInterval(updateCard, 5000);
})
.catch(error => console.error(error));
</script>
</body>
</html>