-
Notifications
You must be signed in to change notification settings - Fork 0
/
closurs.html
92 lines (74 loc) · 1.91 KB
/
closurs.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<style>
input {
width: 200px;
height: 20px;
}
#movies {
height: 400px;
width: 206px;
border: solid 1px black;
overflow: scroll;
}
img {
width: 50px;
height: 50px;
}
</style>
<body>
<input type="text" oninput="debounce(displaydata,1000)" id="query">
<div id="movies"></div>
</body>
</html>
<script>
async function searchmovie() {
try {
let moviename = document.getElementById("query").value
let res = await fetch(`https://www.omdbapi.com/?apikey=d806bd70&s=${moviename}`)
let data = await res.json()
// console.log(data)
return (data.Search)
// displaydata(data)
}
catch (err) {
console.log(err)
}
}
async function displaydata() {
let data = await searchmovie()
if (data === undefined) {
return
}
console.log("data:", data)
appenddata(data)
}
function appenddata(data) {
let movies = document.getElementById("movies")
movies.innerHTML = null
data.map(function (el) {
let div = document.createElement("div")
let img = document.createElement("img")
img.src = el.Poster
let title = document.createElement("p")
title.innerText = el.Title
div.append(title)
movies.append(div)
})
}
let timerid;
function debounce(func, delay) {
if (timerid) {
clearTimeout(timerid)
}
timerid = setTimeout(function () {
func()
}, delay)
}
</script>