-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
132 lines (114 loc) · 4.27 KB
/
script.js
File metadata and controls
132 lines (114 loc) · 4.27 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
// Hide splash after animation completes
window.addEventListener('load', () => {
const splash = document.getElementById('splash');
if (!splash) return;
// Fallback in case animationend doesn't fire
const fallback = setTimeout(() => {
splash.style.display = 'none';
}, 4600);
splash.addEventListener('animationend', e => {
if (e.animationName === 'splash-complete') {
splash.style.display = 'none';
clearTimeout(fallback);
}
});
// Allow skip with Enter or Space
const skip = e => {
if (e.key === 'Enter' || e.key === ' ') {
splash.style.display = 'none';
clearTimeout(fallback);
document.removeEventListener('keydown', skip);
}
};
document.addEventListener('keydown', skip);
});
// Solid nav background on scroll
const nav = document.getElementById('nav');
const handleScroll = () => {
if (!nav) return;
nav.style.background = window.scrollY > 40
? 'rgba(0,0,0,.85)'
: 'linear-gradient(180deg, rgba(0,0,0,.85), rgba(0,0,0,0))';
};
document.addEventListener('scroll', handleScroll, { passive: true });
const initRailKeys = () => {
document.querySelectorAll('.rail').forEach(rail => {
rail.tabIndex = 0;
rail.addEventListener('keydown', e => {
const step = 280;
if (e.key === 'ArrowRight') { rail.scrollBy({ left: step, behavior: 'smooth' }); e.preventDefault(); }
if (e.key === 'ArrowLeft') { rail.scrollBy({ left: -step, behavior: 'smooth' }); e.preventDefault(); }
});
});
};
initRailKeys();
document.querySelectorAll('.btn--play').forEach(btn =>
btn.addEventListener('click', () => document.querySelector('.row')?.scrollIntoView({ behavior: 'smooth' }))
);
document.querySelectorAll('.btn--info').forEach(btn =>
btn.addEventListener('click', () => alert('More info coming soon.'))
);
// Hero elements
const heroElem = document.querySelector('.hero');
const heroTitle = document.querySelector('.hero .title');
const heroDesc = document.querySelector('.hero .desc');
const heroTag = document.querySelector('.hero .tag');
const heroSlides = [
{
img: "https://image.tmdb.org/t/p/w1280/aw4FOsWr2FY373nKSxbpNi3fz4F.jpg",
tag: "Critics Choice",
title: "Mission: Impossible – Fallout",
desc: "In this film that follows Ethan Hunt as he races against time to prevent a global catastrophe involving stolen plutonium and a terrorist group known as the Apostles"
}
];
let heroIndex = 0;
// Image brightness detection to toggle text color
function detectImageBrightness(url, cb) {
const img = new Image();
img.crossOrigin = "Anonymous";
img.src = url;
img.onload = function() {
const canvas = document.createElement("canvas");
canvas.width = img.width; canvas.height = img.height;
const ctx = canvas.getContext('2d');
ctx.drawImage(img, 0, 0, canvas.width, canvas.height);
const data = ctx.getImageData(0, 0, canvas.width, canvas.height).data;
let r = 0, g = 0, b = 0, count = 0;
for (let i = 0; i < data.length; i += 32) {
r += data[i]; g += data[i + 1]; b += data[i + 2]; count++;
}
const avg = (r + g + b) / count / 3;
cb(avg > 160);
};
}
function setHeroSlide(idx) {
if (!heroElem || !heroSlides[idx]) return;
heroElem.classList.add('fade');
setTimeout(() => {
heroElem.style.backgroundImage = `url('${heroSlides[idx].img}')`;
if (heroTitle) heroTitle.textContent = heroSlides[idx].title;
if (heroDesc) heroDesc.textContent = heroSlides[idx].desc;
if (heroTag) heroTag.textContent = heroSlides[idx].tag;
detectImageBrightness(heroSlides[idx].img, (isLight) => {
if (isLight) heroElem.classList.add('light-text');
else heroElem.classList.remove('light-text');
});
heroElem.classList.remove('fade');
}, 700); // half the transition time
}
setHeroSlide(heroIndex);
function handleSearch(e) {
e.preventDefault();
const q = document.getElementById('navSearch').value.trim();
if (!q) return;
alert(`Search: ${q}`);
}
document.addEventListener('keydown', (e) => {
if (e.key === '/' && !/input|textarea|select/i.test(document.activeElement.tagName)) {
e.preventDefault();
const el = document.getElementById('navSearch');
if (el) {
el.focus();
}
}
});