Created
October 19, 2023 11:54
-
-
Save AhsanAyaz/61000e255cef5e466dbc3f70c18d521d to your computer and use it in GitHub Desktop.
ReaveaJS Video Full Screen
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- Add this before your HTML's closing body tag --> | |
<script> | |
Reveal.initialize({ | |
controls: true, | |
progress: true, | |
history: true, | |
center: true, | |
plugins: [ | |
RevealMarkdown, | |
RevealHighlight, | |
RevealNotes, | |
RevealMath.KaTeX, | |
], | |
}); | |
// Function to make a video element fullscreen | |
function makeVideoFullScreen(videoElement) { | |
if (videoElement.requestFullscreen) { | |
videoElement.requestFullscreen(); | |
} else if (videoElement.mozRequestFullScreen) { | |
videoElement.mozRequestFullScreen(); | |
} else if (videoElement.webkitRequestFullscreen) { | |
videoElement.webkitRequestFullscreen(); | |
} else if (videoElement.msRequestFullscreen) { | |
videoElement.msRequestFullscreen(); | |
} | |
} | |
// Listen for slide changes | |
Reveal.addEventListener('slidechanged', function (event) { | |
// Get the current slide | |
var currentSlide = event.currentSlide; | |
// Find video elements within the current slide | |
var videos = currentSlide.querySelectorAll('video'); | |
// If there are videos on the current slide, make them fullscreen | |
if (videos.length > 0) { | |
makeVideoFullScreen(videos[0]); | |
} | |
}); | |
// Keyboard event listener for navigating between slides | |
document.addEventListener('keydown', function (event) { | |
// Check if a video is in fullscreen mode | |
if (!document.fullscreenElement) { | |
return; | |
} | |
if (event.code === 'space') { | |
event.preventDefault(); | |
return; | |
} | |
switch (event.key) { | |
case 'ArrowRight': | |
case 'ArrowDown': | |
case 'PageDown': | |
document.exitFullscreen(); | |
// Navigate to the next slide | |
Reveal.next(); | |
break; | |
case 'ArrowUp': | |
case 'ArrowLeft': | |
case 'PageUp': | |
document.exitFullscreen(); | |
// Navigate to the previous slide | |
Reveal.prev(); | |
break; | |
} | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment