-
Notifications
You must be signed in to change notification settings - Fork 0
/
imagesearchapp.html
197 lines (194 loc) · 5.74 KB
/
imagesearchapp.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Image Search App</title>
<link rel="stylesheet" href="imagesearch.css">
</head>
<body>
<h1>Image Search App</h1>
<form>
<input type="text" id="search-input" placeholder="Search for images...">
<button id="search-button">Search</button>
</form>
<div class="Search-result">
<!-- <div class="image">
<img src="https://images.unsplash.com/photo-1433086966358-54859d0ed716?q=80&w=1374&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D" alt="image">
<a href="https://unsplash.com/photos/gray-concrete-bridge-and-waterfalls-during-daytime-cssvEZacHvQ" target="_blank">an image of nature</a>
</div>
<div class="image">
<img src="https://images.unsplash.com/photo-1433086966358-54859d0ed716?q=80&w=1374&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D" alt="image">
<a href="https://unsplash.com/photos/gray-concrete-bridge-and-waterfalls-during-daytime-cssvEZacHvQ" target="_blank">an image of nature</a>
</div>
<div class="image">
<img src="https://images.unsplash.com/photo-1433086966358-54859d0ed716?q=80&w=1374&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D" alt="image">
<a href="https://unsplash.com/photos/gray-concrete-bridge-and-waterfalls-during-daytime-cssvEZacHvQ" target="_blank">an image of nature</a>
</div> -->
</div>
<button id="showmore">Show more</button>
<script src="imagesearch.js"></script>
</body>
</html>
<!-- *{
padding: 0;
margin: 0;
box-sizing: border-box;
}
body{
background-color: #f9f9f9;
font-family: Arial, Helvetica, sans-serif;
line-height: 1.6;
}
h1{
font-size: 5.714285714285714vh;
font-weight: bold;
text-align: center;
margin-top: 6.349206349206349vh;
margin-bottom: 9.523809523809524vh;
}
form{
display: flex;
justify-content: center;
align-items: center;
margin-bottom: 9.523809523809524vh;
}
#search-input{
width: 60%;
max-width: 63.492063492063494vh;
padding: 1.6vh 3.1746031746031744vh;
border: none;
box-shadow: 0 0 5px rgba(0,0,0,0.2);
border-radius: .6vh;
font-size: 2.857142857142857vh;
color: #333;
}
#search-button{
padding: 1.6vh 3.1746031746031744vh;
background-color: #4caf50;
color: white;
border: none;
font-size: 2.857142857142857vh;
box-shadow: 0 0 5px rgba(0,0,0,0.2);
cursor: pointer;
border-radius: .6vh;
transition: background-color .3s ease-in-out;
}
#search-button:hover{
background-color: #3e8e41;
}
.image img{
width: 100%;
height: 31.746031746031747vh;
object-fit: cover;
transition: transform .3s ease-in-out;
}
.image:hover img{
transform: scale(1.05);
}
.Search-result{
display: flex;
flex-wrap: wrap;
justify-content: space-between;
max-width: 1200px;
margin: 0 auto;
padding: 20px;
}
.image a{
padding: 1.6vh;
display: block;
color: #333;
text-decoration: none;
transition: background-color .3s ease-in-out;
}
.image:hover a{
background-color: rgba(0,0,0,0.1);
}
.image{
margin-bottom: 9.523809523809524vh;
width: 30%;
border-radius: .6vh;
box-shadow: 0 0 5px rgba(0,0,0,0.2);
overflow: hidden;
}
#showmore{
background-color: #008cba;
border: none;
color: white;
display: inline-block;
padding: 10px 20px;
text-align: center;
margin:20px auto;
display: block;
border-radius: .6vh;
cursor: pointer;
transition: background-color .3s ease-in-out;
display: none;
}
@media screen and (max-width:768px){
.image{
width: 45%;
}
}
@media screen and (max-width:480px){
.image{
width: 100%;
}
form{
flex-direction: column;
}
#search-input{
margin-bottom:20px ;
width: 90vw;
}
button{
width: 90vw;
}
}
#showmore:hover{
background-color: #0077b5;
}
/* .btn{
display: flex;
justify-content: center;
} */
const acesskey="p06CcIuFssA-AyFikIxgFC1EQtci8twKb6vpeUbco9I";
const formE1=document.querySelector("form");
const inputE1=document.querySelector("#search-input");
const searchResult=document.querySelector(".Search-result");
const btn=document.querySelector("#showmore");
let inputData="";
let page=1;
async function searchImages(){
inputData=inputE1.value;
const url=`https://api.unsplash.com/search/photos?page=${page}&query=${inputData}&client_id=${acesskey}`
console.log(url);
const response=await fetch(url);
const data=await response.json();
if(page===1){
searchResult.innerHTML="";
}
const results=data.results;
results.map((result)=>{
const imageWrapper=document.createElement("div");
imageWrapper.classList.add("Search-result");
const image=document.createElement("img");
image.src=result.urls.small;
image.alt=result.alt_description;
const anchor=document.createElement("a");
anchor.href=result.links.html;
anchor.target="_blank";
anchor.textContent=result.alt_description;
imageWrapper.appendChild(image);
imageWrapper.appendChild(anchor);
searchResult.appendChild(imageWrapper);
});
if(page>1){
btn.style.display=block;
}
}
formE1.addEventListener("submit",(event)=>{
event.preventDefault();
page=1;
searchImages();
}) -->