-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMovieSearch.html
More file actions
211 lines (180 loc) · 6.7 KB
/
MovieSearch.html
File metadata and controls
211 lines (180 loc) · 6.7 KB
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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Movie App</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;700&display=swap" rel="stylesheet">
<style>
body {
font-family: 'Roboto', sans-serif;
background-color: #121212;
color: white;
margin: 0;
padding: 0;
}
.banner {
text-align: center;
padding: 80px 20px;
background: linear-gradient(to bottom, rgba(0, 0, 0, 0.6), rgba(0, 0, 0, 0.9)), url('https://via.placeholder.com/1500x700') center center no-repeat;
background-size: cover;
}
.banner h1 {
font-size: 55px;
font-weight: bold;
color: white;
}
.banner p {
font-size: 24px;
margin-bottom: 30px;
}
.search-bar {
display: flex;
justify-content: center;
margin-bottom: 50px;
gap: 10px;
}
.search-bar input {
width: 60%;
padding: 15px 25px;
border-radius: 30px;
border: 1px solid #444;
background-color: #333;
color: white;
font-size: 18px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.4);
}
.search-bar button {
padding: 15px 30px;
border-radius: 30px;
border: none;
background-color: #e50914;
color: white;
font-size: 18px;
cursor: pointer;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.4);
}
.search-bar button:hover {
background-color: #b20710;
}
.movie-container {
display: flex;
flex-wrap: wrap;
justify-content: center;
gap: 20px;
padding: 30px;
}
.movie-card {
width: 250px;
background-color: #222;
border-radius: 15px;
overflow: hidden;
transition: transform 0.3s ease, box-shadow 0.3s ease;
cursor: pointer;
box-shadow: 0 4px 10px rgba(0, 0, 0, 0.5);
}
.movie-card:hover {
transform: scale(1.05);
box-shadow: 0 8px 15px rgba(0, 0, 0, 0.7);
}
.movie-card img {
width: 100%;
height: 375px;
object-fit: cover;
}
.movie-title {
padding: 15px;
text-align: center;
font-size: 18px;
font-weight: bold;
color: #e50914;
}
.movie-not-found {
text-align: center;
color: #e50914;
font-size: 24px;
margin-top: 30px;
}
.loading-spinner {
text-align: center;
margin-top: 30px;
}
</style>
</head>
<body>
<!-- Banner Section -->
<div class="banner">
<h1>Discover Your Favorite Movies</h1>
<p>Search and explore a wide variety of films and shows</p>
</div>
<!-- Search Bar Section -->
<div class="container search-bar">
<input id="movieSearch" class="form-control" type="text" placeholder="Search for movies..."
onkeyup="searchMovies()">
<button onclick="searchMovies()">Search</button>
</div>
<!-- Movie Cards Section -->
<div class="container movie-container" id="movieContainer">
<!-- Movies will be shown here dynamically -->
</div>
<!-- Movie Not Found Message -->
<div class="movie-not-found" id="notFoundMessage" style="display: none;">
<p>No movies found. Please try again.</p>
</div>
<!-- Loading Spinner -->
<div class="loading-spinner" id="loadingSpinner" style="display: none;">
<div class="spinner-border text-danger" role="status">
<span class="visually-hidden">Loading...</span>
</div>
</div>
<script>
const apiKey = '460cabf2'; // Your OMDb API key
function searchMovies() {
const query = document.getElementById('movieSearch').value.trim();
// Hide loading spinner and reset the previous results
document.getElementById('loadingSpinner').style.display = 'block';
document.getElementById('movieContainer').innerHTML = '';
document.getElementById('notFoundMessage').style.display = 'none';
// If the search query is empty, stop the process
if (query === '') {
document.getElementById('loadingSpinner').style.display = 'none';
return;
}
// Fetch data from OMDb API
fetch(`https://www.omdbapi.com/?s=${query}&apikey=${apiKey}`)
.then(response => response.json())
.then(data => {
document.getElementById('loadingSpinner').style.display = 'none';
if (data.Search) {
const movies = data.Search;
// Display the movie cards
movies.forEach(movie => {
if (movie.Poster !== 'N/A') {
const movieCard = `
<div class="movie-card">
<img src="${movie.Poster}" alt="${movie.Title}">
<div class="movie-title">${movie.Title}</div>
</div>
`;
document.getElementById('movieContainer').insertAdjacentHTML('beforeend', movieCard);
}
});
// If no movies are found with valid posters
if (document.getElementById('movieContainer').innerHTML === '') {
document.getElementById('notFoundMessage').style.display = 'block';
}
} else {
document.getElementById('notFoundMessage').style.display = 'block';
}
})
.catch(err => {
document.getElementById('loadingSpinner').style.display = 'none';
console.error('Error fetching data:', err);
});
}
</script>
<script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.11.6/dist/umd/popper.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/js/bootstrap.min.js"></script>
</body>
</html>