-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
91 lines (84 loc) · 2.38 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
<html>
<head>
<title>Flickr Search</title>
<style>
@keyframes rotation {
from {
transform: rotate(0deg);
}
to {
transform: rotate(359deg);
}
}
body {
background-color: #eee;
}
.search-container {
display: flex;
gap:12px;
margin-bottom:12px;
}
.input{
font-size: medium;
padding:20px
}
.go {
font-size: medium;
padding:20px
}
.spinner {
animation: rotation 2.5s infinite linear;
max-width: 60px;
display: none;
}
.thumbs {
display: flex;
flex-wrap: wrap;
}
.photo {
max-width: 150px;
position:relative;
}
.views {
position: absolute;
top: 50%;
left: 50%;
font-size: x-large;
font-weight: bolder;
color: white;
transform: translate(-50%,-50%);
-ms-transform: translate(-50%,-50%);
}
</style>
<body>
<h1>Flickr Search</h1>
<div class=search-container>
<input class=input id=search type='text'>
<button onclick="getFlickr()" class='go'>Go</button>
<img id=spinid class=spinner src="/pngwing.com.png">
</div>
<div id=display class='thumbs'></div>
<script>
async function getFlickr() {
const key = '4e258a4396bf5ba0448b2e2fe574034e'
const flickrAPI = 'https://api.flickr.com/services/rest/?method=flickr.photos.search&format=json&nojsoncallback=1&extras=views&api_key='+`${key}`
let tags = `&tags='${document.getElementById("search").value}'`
tags = tags.replace(/ /g, ',');
let photos = ''
document.getElementById("display").innerHTML = photos
document.getElementById("spinid").style.display = "block"
await fetch(flickrAPI+tags)
.then(response => {
document.getElementById("spinid").style.display = "none"
return response.json()
})
.then(data => {
for (let each of data.photos.photo){
photos += `<div class=photo><div class=views>${each.views}</div><img src="https://live.staticflickr.com/${each.server}/${each.id}_${each.secret}_q.jpg></div>`
}
document.getElementById("display").innerHTML = photos
})
}
</script>
</body>
</html>