forked from jmschrack/Dark-Portfolio-Template-11ty
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.njk.bak.1759496056
More file actions
127 lines (111 loc) · 4.02 KB
/
Copy pathindex.njk.bak.1759496056
File metadata and controls
127 lines (111 loc) · 4.02 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
---
layout: layouts/base.njk
eleventyNavigation:
key: Home
order: 1
hero:
name: "Yousef Mohamed"
role: "Filmmaker"
subrole: "Multidisciplinary Visual Artist | Concept Artist | Graphic Designer | 2D Animator | Editor | VFX Generalist"
---
<!-- HERO -->
<section class="hero">
<div class="hero-bg" id="showreel">
{% for item in showreel %}
{% if item.type == "video" %}
<video class="slide{% if loop.index0 == 0 %} active{% endif %}" preload="auto" muted playsinline>
<source src="{{ item.src | url }}" type="{{ item.mime or 'video/mp4' }}">
</video>
{% else %}
<img class="slide{% if loop.index0 == 0 %} active{% endif %}" src="{{ item.src | url }}" alt="showreel {{ loop.index }}" loading="{% if loop.index0 == 0 %}eager{% else %}lazy{% endif %}">
{% endif %}
{% endfor %}
</div>
<div class="hero-copy">
<h1 class="hero-title">{{ hero.name }}</h1>
<p class="hero-role">{{ hero.role }}</p>
<div class="hero-subrole">{{ hero.subrole }}</div>
</div>
</section>
<!-- SLIDER: صورة=1s | فيديو=لنهايته | ترتيب ثابت | Loop | أول سلايد فوري -->
<script>
document.addEventListener("DOMContentLoaded", () => {
const slides = Array.from(document.querySelectorAll("#showreel .slide"));
if (!slides.length) return;
const IMAGE_MS = 1000; // مدة الصورة
const FADE_MS = 200; // ترانزيشن بسيط
let i = 0, timer = null, locking = false;
// قياسات بدون قص
slides.forEach(el => {
if (el.tagName === "IMG") {
el.style.objectFit = "contain";
el.style.width = "100%";
el.style.height = "100%";
el.decoding = "async";
} else if (el.tagName === "VIDEO") {
el.style.objectFit = "contain";
el.style.width = "100%";
el.style.height = "100%";
el.muted = true;
el.playsInline = true;
el.preload = "auto";
}
});
const clear = (el) => {
if (timer) { clearTimeout(timer); timer = null; }
if (el && el.tagName === "VIDEO") {
el.onended = el.onerror = el.onabort = el.onplaying = null;
}
};
// حمّل السلايد التالي (للصور) لتقليل الانتظار
const preloadNext = (k) => {
const n = slides[(k+1) % slides.length];
if (!n || n.tagName !== "IMG") return;
if (!n.dataset.preloaded && n.getAttribute("src")) {
const im = new Image();
im.src = n.getAttribute("src");
n.dataset.preloaded = "1";
}
};
function activate(n){
if (locking) return;
locking = true;
const prev = slides[i];
clear(prev);
prev && prev.classList.remove("active");
i = (n + slides.length) % slides.length;
const el = slides[i];
el.classList.add("active");
// افتح القفل بعد انتهاء الفيد
setTimeout(() => { locking = false; }, FADE_MS);
preloadNext(i);
if (el.tagName === "VIDEO") {
try { el.currentTime = 0; el.load(); } catch(_) {}
el.onplaying = () => { if (timer) { clearTimeout(timer); timer = null; } };
el.onended = el.onerror = el.onabort = () => activate(i+1);
const p = el.play?.();
if (p && p.catch) {
// لو autoplay اترفض، اديله 3 ثواني وامشي للسلايد اللي بعده
p.catch(() => { timer = setTimeout(() => activate(i+1), 3000); });
}
} else {
timer = setTimeout(() => activate(i+1), IMAGE_MS);
}
}
// أول سلايد يُفَعَّل فورًا من غير انتظار
activate(0);
});
</script>
<style>
/* === Slider minimal CSS (no crop) === */
.hero{position:relative;min-height:70vh;display:grid;place-items:center;overflow:hidden;background:#000}
.hero .hero-bg{position:absolute;inset:0}
#showreel{position:absolute;inset:0;overflow:hidden}
#showreel .slide{
position:absolute;inset:0;
opacity:0; transition:opacity .2s ease;
background:#000; display:block;
}
#showreel .slide.active{opacity:1}
#showreel img.slide, #showreel video.slide{width:100%;height:100%;object-fit:contain;background:#000;display:block}
</style>