1
0
mirror of https://github.com/hakimel/reveal.js.git synced 2025-01-16 21:08:28 +01:00

allow same background video to continue playing across multiple slides #3189 #2882

Co-authored-by: Chi Vong <chivongv@gmail.com>
This commit is contained in:
Hakim El Hattab 2024-03-08 14:01:48 +01:00
parent 6ef138b61f
commit a29a9c71ae
5 changed files with 24 additions and 5 deletions

2
dist/reveal.esm.js vendored

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

2
dist/reveal.js vendored

File diff suppressed because one or more lines are too long

2
dist/reveal.js.map vendored

File diff suppressed because one or more lines are too long

View File

@ -353,6 +353,25 @@ export default class Backgrounds {
let currentBackgroundHash = currentBackground.getAttribute( 'data-background-hash' );
if( currentBackgroundHash && currentBackgroundHash === previousBackgroundHash && currentBackground !== this.previousBackground ) {
this.element.classList.add( 'no-transition' );
// If multiple slides have the same background video, we carry
// the <video> element forward so that it doesn't restart
const currentVideo = currentBackground.querySelector( 'video' );
if( currentVideo && this.previousBackground ) {
const previousVideo = this.previousBackground.querySelector( 'video' );
if( previousVideo ) {
const currentVideoParent = currentVideo.parentNode;
const previousVideoParent = previousVideo.parentNode;
// Swap the two videos
previousVideoParent.appendChild( currentVideo );
currentVideoParent.appendChild( previousVideo );
// Resume playing if the previous video was playing
previousVideo.play();
}
}
}
this.previousBackground = currentBackground;
@ -368,7 +387,7 @@ export default class Backgrounds {
// Allow the first background to apply without transition
setTimeout( () => {
this.element.classList.remove( 'no-transition' );
}, 1 );
}, 10 );
}