Skip to content

Commit

Permalink
allow same background video to continue playing across multiple slides
Browse files Browse the repository at this point in the history
…#3189 #2882

Co-authored-by: Chi Vong <chivongv@gmail.com>
  • Loading branch information
hakimel and chivongv committed Mar 8, 2024
1 parent 6ef138b commit a29a9c7
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 5 deletions.
2 changes: 1 addition & 1 deletion dist/reveal.esm.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/reveal.esm.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/reveal.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/reveal.js.map

Large diffs are not rendered by default.

21 changes: 20 additions & 1 deletion js/controllers/backgrounds.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 );

}

Expand Down

0 comments on commit a29a9c7

Please sign in to comment.