Spiele im Einstieg ein freigegebenes Video stumm auf der Fläche des Fotos ab
Neue optionale Auswahl refs.video am Hero (Variante Foto mit Textfläche). Gespielt wird der für die Website freigegebene Clip nach der Regel der Karte (Trailer, Vorschauclip, Website-Datei des Films); nie der vollständige Film. Start nach dem Laden, Schaltfläche zum Anhalten, Foto als Rückfall, kein Selbststart bei reduzierter Bewegung, Datensparmodus und 2G. Keine Migration. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
437bb394b2
commit
73126fec0c
11 files changed
+731
-5
No files matched your search
@@ -48,6 +48,52 @@ .lf-hero__photo {
|
||||
border-radius: inherit;
|
||||
}
|
||||
|
||||
/*
|
||||
* Video auf der Fläche des Fotos (nur photo_split, resources/js/hero-video.js). Das Foto bleibt darunter sichtbar, bis
|
||||
* das erste Videobild da ist; ohne JavaScript, bei Fehlern und ohne freigegebenen Clip bleibt es beim Foto.
|
||||
*/
|
||||
.lf-hero__video {
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
z-index: -2;
|
||||
inline-size: 100%;
|
||||
block-size: 100%;
|
||||
max-inline-size: none;
|
||||
object-fit: cover;
|
||||
object-position: var(--lf-hero-focus-x) var(--lf-hero-focus-y);
|
||||
border-radius: inherit;
|
||||
opacity: 0;
|
||||
transition: opacity 0.4s ease;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
.lf-hero.is-hero-started .lf-hero__video { opacity: 1; }
|
||||
|
||||
.lf-hero__video-toggle {
|
||||
position: absolute;
|
||||
inset: 12px 12px auto auto;
|
||||
z-index: 2;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
min-block-size: 44px;
|
||||
padding: 8px 14px 8px 10px;
|
||||
border: 0;
|
||||
border-radius: 999px;
|
||||
color: #fff;
|
||||
background: rgb(3 37 81 / 86%);
|
||||
font: 600 0.8125rem/1.2 var(--lf-font-ui, system-ui, sans-serif);
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.lf-hero__video-toggle[hidden] { display: none; }
|
||||
.lf-hero__video-toggle:hover { background: var(--lf-navy-deep, var(--lf-hero-navy)); }
|
||||
.lf-hero__video-toggle:focus-visible { outline: 3px solid var(--lf-hero-yellow); outline-offset: 3px; }
|
||||
.lf-hero__video-icon { inline-size: 20px; block-size: 20px; }
|
||||
.lf-hero__video-pause,
|
||||
.lf-hero__video-toggle[aria-pressed="true"] .lf-hero__video-play { display: none; }
|
||||
.lf-hero__video-toggle[aria-pressed="true"] .lf-hero__video-pause { display: inline; }
|
||||
|
||||
.lf-hero--photo-split::before {
|
||||
content: '';
|
||||
position: absolute;
|
||||
@@ -189,6 +235,7 @@ @container lf-hero (max-width: 859.99px) {
|
||||
.lf-hero--height-normal,
|
||||
.lf-hero--height-large { min-block-size: 0; }
|
||||
.lf-hero__photo { position: relative; display: block; block-size: auto; aspect-ratio: 16 / 9; }
|
||||
.lf-hero__video { inset: 0 0 auto 0; block-size: auto; aspect-ratio: 16 / 9; border-radius: inherit; }
|
||||
.lf-hero--photo-split::before { display: none; }
|
||||
.lf-hero__inner { padding: clamp(1.2rem, 3.5cqi, 2rem); padding-block-end: 2.4rem; }
|
||||
.lf-hero__copy { max-inline-size: 100%; }
|
||||
@@ -204,6 +251,7 @@ @container lf-hero (max-width: 440px) {
|
||||
}
|
||||
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
.lf-hero__video { transition: none; }
|
||||
.lf-hero__button { transition: none; }
|
||||
.lf-hero__button:hover { transform: none; }
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
import Hls from 'hls.js';
|
||||
import './site-nav.js';
|
||||
import './card-clip.js';
|
||||
import './hero-video.js';
|
||||
|
||||
function attachPlayback(video) {
|
||||
if (!(video instanceof HTMLVideoElement) || video.dataset.playbackReady === '1') {
|
||||
|
||||
@@ -0,0 +1,203 @@
|
||||
/*
|
||||
* Video im Einstieg (Hero, Variante „Foto mit Textfläche“).
|
||||
*
|
||||
* Ein Einstieg mit [data-hero-video] trägt einen für die Website freigegebenen Clip (data-clip-src). Der Clip
|
||||
* - startet stumm von selbst, sobald die Seite geladen ist (die Quelle wird erst dann gesetzt, preload="none"),
|
||||
* - lässt das Foto stehen, bis das erste Videobild da ist (Klasse is-hero-started), und fällt bei Fehlern auf das Foto zurück,
|
||||
* - startet bei „reduzierte Bewegung“, im Datensparmodus und bei sehr langsamer Verbindung nie von selbst, sondern nur
|
||||
* auf ausdrückliche Bedienung, dann ohne Schleife,
|
||||
* - hat immer eine Schaltfläche zum Anhalten und Abspielen (WCAG 2.2.2),
|
||||
* - hält an, sobald der Einstieg aus dem Bild scrollt oder der Tab verborgen ist, und läuft danach nur weiter, wenn
|
||||
* er von selbst lief und nicht angehalten wurde.
|
||||
* Ohne JavaScript bleibt es beim Foto; die Schaltfläche erscheint erst, wenn dieses Skript sie freigibt.
|
||||
*/
|
||||
const REDUCED = window.matchMedia ? window.matchMedia('(prefers-reduced-motion: reduce)') : { matches: false };
|
||||
|
||||
function connection() {
|
||||
return navigator.connection || null;
|
||||
}
|
||||
|
||||
function mayAutoplay() {
|
||||
const link = connection();
|
||||
|
||||
if (REDUCED.matches) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (link && (link.saveData || /(^|-)2g$/.test(String(link.effectiveType || '')))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function whenLoaded(callback) {
|
||||
const run = () => {
|
||||
if ('requestIdleCallback' in window) {
|
||||
window.requestIdleCallback(callback, { timeout: 2500 });
|
||||
} else {
|
||||
window.setTimeout(callback, 200);
|
||||
}
|
||||
};
|
||||
|
||||
if (document.readyState === 'complete') {
|
||||
run();
|
||||
} else {
|
||||
window.addEventListener('load', run, { once: true });
|
||||
}
|
||||
}
|
||||
|
||||
function setup(hero) {
|
||||
if (hero.dataset.heroVideoReady === '1') {
|
||||
return;
|
||||
}
|
||||
|
||||
const video = hero.querySelector('video.lf-hero__video');
|
||||
const toggle = hero.querySelector('[data-hero-toggle]');
|
||||
const source = hero.dataset.clipSrc;
|
||||
|
||||
if (!(video instanceof HTMLVideoElement) || !toggle || !source) {
|
||||
return;
|
||||
}
|
||||
|
||||
hero.dataset.heroVideoReady = '1';
|
||||
|
||||
const title = hero.dataset.clipTitle || '';
|
||||
let playing = false;
|
||||
let wantsPlay = false; // läuft (oder lief) nach Absicht der Besucherin oder des Besuchers bzw. von selbst
|
||||
let failed = false;
|
||||
let armed = mayAutoplay(); // darf noch von selbst starten (einmal, sobald geladen und im Bild)
|
||||
let loaded = false;
|
||||
|
||||
function inView() {
|
||||
const box = hero.getBoundingClientRect();
|
||||
|
||||
return box.bottom > 0 && box.top < window.innerHeight;
|
||||
}
|
||||
|
||||
function label() {
|
||||
toggle.setAttribute('aria-pressed', playing ? 'true' : 'false');
|
||||
toggle.setAttribute('aria-label', (playing ? 'Video anhalten: ' : 'Video abspielen: ') + title);
|
||||
}
|
||||
|
||||
function play(auto) {
|
||||
if (failed) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!video.getAttribute('src')) {
|
||||
video.src = source;
|
||||
}
|
||||
|
||||
video.muted = true;
|
||||
video.loop = !REDUCED.matches;
|
||||
wantsPlay = true;
|
||||
playing = true;
|
||||
label();
|
||||
|
||||
const attempt = video.play();
|
||||
|
||||
if (attempt && typeof attempt.catch === 'function') {
|
||||
attempt.catch(() => {
|
||||
// Vom Browser nicht erlaubt: das Foto bleibt, die Schaltfläche bietet das Abspielen an.
|
||||
playing = false;
|
||||
wantsPlay = false;
|
||||
label();
|
||||
});
|
||||
}
|
||||
|
||||
hero.dataset.heroAuto = auto ? '1' : '0';
|
||||
}
|
||||
|
||||
function pause(byUser) {
|
||||
playing = false;
|
||||
|
||||
if (byUser) {
|
||||
wantsPlay = false;
|
||||
}
|
||||
|
||||
video.pause();
|
||||
label();
|
||||
}
|
||||
|
||||
video.addEventListener('playing', () => hero.classList.add('is-hero-started'));
|
||||
|
||||
video.addEventListener('ended', () => {
|
||||
playing = false;
|
||||
wantsPlay = false;
|
||||
hero.classList.remove('is-hero-started');
|
||||
label();
|
||||
});
|
||||
|
||||
video.addEventListener('error', () => {
|
||||
failed = true;
|
||||
playing = false;
|
||||
hero.classList.remove('is-hero-started');
|
||||
hero.classList.add('is-hero-failed');
|
||||
toggle.hidden = true;
|
||||
});
|
||||
|
||||
toggle.addEventListener('click', () => {
|
||||
if (playing) {
|
||||
pause(true);
|
||||
} else {
|
||||
play(false);
|
||||
}
|
||||
});
|
||||
|
||||
if ('IntersectionObserver' in window) {
|
||||
new IntersectionObserver((entries) => {
|
||||
entries.forEach((entry) => {
|
||||
if (entry.isIntersecting) {
|
||||
if (armed && loaded && !wantsPlay && !document.hidden) {
|
||||
armed = false;
|
||||
play(true);
|
||||
} else if (wantsPlay && !playing && !document.hidden) {
|
||||
play(hero.dataset.heroAuto === '1');
|
||||
}
|
||||
} else if (playing) {
|
||||
pause(false);
|
||||
}
|
||||
});
|
||||
}, { threshold: 0.15 }).observe(hero);
|
||||
}
|
||||
|
||||
document.addEventListener('visibilitychange', () => {
|
||||
if (document.hidden && playing) {
|
||||
pause(false);
|
||||
} else if (!document.hidden && wantsPlay && !playing && inView()) {
|
||||
play(hero.dataset.heroAuto === '1');
|
||||
}
|
||||
});
|
||||
|
||||
label();
|
||||
toggle.hidden = false;
|
||||
hero.classList.add('is-hero-ready');
|
||||
|
||||
if (armed) {
|
||||
whenLoaded(() => {
|
||||
loaded = true;
|
||||
|
||||
if (armed && !failed && !wantsPlay && inView() && !document.hidden) {
|
||||
armed = false;
|
||||
play(true);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function scan(root) {
|
||||
if (root instanceof Element) {
|
||||
if (root.matches('[data-hero-video]')) {
|
||||
setup(root);
|
||||
}
|
||||
|
||||
root.querySelectorAll('[data-hero-video]').forEach(setup);
|
||||
}
|
||||
}
|
||||
|
||||
scan(document.documentElement);
|
||||
|
||||
new MutationObserver((records) => {
|
||||
records.forEach((record) => record.addedNodes.forEach(scan));
|
||||
}).observe(document.documentElement, { childList: true, subtree: true });
|
||||
@@ -3,19 +3,33 @@
|
||||
Varianten: photo_split (Foto mit heller Textfläche), editorial_solid (Navy-Markenfläche ohne Foto).
|
||||
Höhen compact/normal/large sind Mindesthöhen ab 860 px Containerbreite; darunter Sicherheitsumbruch.
|
||||
Das Bild des ersten Widgets der Seite wird sofort geladen, alle anderen verzögert.
|
||||
Video (nur photo_split): stummer, freigegebener Clip auf der Fläche des Fotos (HeroVideo). Das <video> bekommt seine
|
||||
Quelle erst nach dem Laden der Seite (resources/js/hero-video.js, preload="none"); das Foto bleibt Rückfall.
|
||||
Der Clip ist Beiwerk; Überschrift und Text stehen daneben, das Video ist für Hilfstechnik verborgen und die
|
||||
Schaltfläche trägt die Bedeutung.
|
||||
--}}
|
||||
@php
|
||||
$layout = $variant === 'editorial_solid' ? 'editorial-solid' : 'photo-split';
|
||||
$heightClass = in_array($height, ['compact', 'normal', 'large'], true) ? $height : 'normal';
|
||||
$tag = \App\Domain\Cms\Widgets\Support\PremiumFields::headingTag($settings, ! empty($first));
|
||||
$loading = ! empty($first) ? 'loading="eager" fetchpriority="high"' : 'loading="lazy"';
|
||||
$videoUrl = $layout === 'photo-split' ? ($video['url'] ?? null) : null;
|
||||
$videoTitle = $video['title'] ?? '';
|
||||
@endphp
|
||||
<div class="lf-hero-host">
|
||||
<div class="lf-hero lf-hero--{{ $layout }} lf-hero--height-{{ $heightClass }} lf-hero--accent-{{ $accent }}"
|
||||
style="--lf-hero-focus-x: {{ $focus['x'] }}%; --lf-hero-focus-y: {{ $focus['y'] }}%">
|
||||
style="--lf-hero-focus-x: {{ $focus['x'] }}%; --lf-hero-focus-y: {{ $focus['y'] }}%"
|
||||
@if ($videoUrl !== null) data-hero-video data-clip-src="{{ $videoUrl }}" data-clip-title="{{ $videoTitle }}" @endif>
|
||||
@if ($layout === 'photo-split' && $imageUrl)
|
||||
<img class="lf-hero__photo" src="{{ $imageUrl }}" alt="{{ $imageAlt ?? '' }}" {!! $loading !!} decoding="async">
|
||||
@endif
|
||||
@if ($videoUrl !== null)
|
||||
<video class="lf-hero__video" muted loop playsinline preload="none" disablepictureinpicture disableremoteplayback tabindex="-1" aria-hidden="true"></video>
|
||||
<button type="button" class="lf-hero__video-toggle" aria-pressed="false" data-hero-toggle aria-label="Video abspielen: {{ $videoTitle }}" hidden>
|
||||
<svg class="lf-hero__video-icon" viewBox="0 0 24 24" focusable="false" aria-hidden="true"><path class="lf-hero__video-play" d="M8 5.5v13l11-6.5z" fill="currentColor"/><path class="lf-hero__video-pause" d="M7 5h4v14H7zM13 5h4v14h-4z" fill="currentColor"/></svg>
|
||||
<span aria-hidden="true">Video</span>
|
||||
</button>
|
||||
@endif
|
||||
<div class="lf-hero__inner">
|
||||
<div class="lf-hero__copy">
|
||||
@if ($accent === 'rays')
|
||||
@@ -44,3 +58,6 @@
|
||||
</div>
|
||||
</div>
|
||||
@include('widgets.partials.image-notice')
|
||||
@if ($context->preview && ! empty($video['notice']))
|
||||
<p class="preview-note">{{ $video['notice'] }}</p>
|
||||
@endif
|
||||
Reference in new issue
Block a user