-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
72 lines (56 loc) · 2.18 KB
/
script.js
File metadata and controls
72 lines (56 loc) · 2.18 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
const navMenu = document.querySelector(".navmenu");
const html = document.querySelector("html");
window.addEventListener("scroll", function(){
let header = this.document.querySelector("header");
header.classList.toggle('sticky', window.scrollY > 0);
});
//Search function
const searchInput = document.querySelector('.search-input');
const movies = document.querySelectorAll('.movie');
const categories = document.querySelectorAll('.category-title');
const searchContainer = document.querySelector('.search-container');
const mainFront = document.querySelector('.picture-center');
document.addEventListener("DOMContentLoaded", function() {
const searchInput = document.querySelector('.search-input');
const movies = document.querySelectorAll('.movie');
const categories = document.querySelectorAll('.category-title');
searchInput.addEventListener('input', function(event) {
const searchText = event.target.value.toLowerCase().trim();
// Zuerst alle Kategorien ausblenden
categories.forEach(category => {
category.style.display = 'none';
});
movies.forEach(movie => {
const title = movie.getAttribute('data-title').toLowerCase();
if (title.includes(searchText)) {
movie.style.display = 'block';
// Die Kategorie dieser Filme anzeigen
const category = movie.closest('.movie-center').previousElementSibling;
category.style.display = 'block';
} else {
movie.style.display = 'none';
}
});
});
});
function resetSearch() {
searchInput.value = '';
categories.forEach(category => {
category.style.display = 'block';
});
movies.forEach(movie => {
movie.style.display = 'block';
});
}
function searchClick() {
searchContainer.style.display = 'flex';
mainFront.style.display = 'none';
searchInput.focus();
document.addEventListener('click', function(event) {
if (document.activeElement !== searchInput) {
searchContainer.style.display = 'none';
mainFront.style.display = 'flex';
resetSearch();
}
});
}