Bläddra i källkod

auto play/pause html5 media when entering/leaving slide (#388)

Hakim El Hattab 11 år sedan
förälder
incheckning
32736a791c
2 ändrade filer med 37 tillägg och 1 borttagningar
  1. 36 0
      js/reveal.js
  2. 1 1
      js/reveal.min.js

+ 36 - 0
js/reveal.js

@@ -1147,6 +1147,10 @@ var Reveal = (function(){
 			}
 		}
 
+		// Handle embedded content
+		stopEmbeddedContent( previousSlide );
+		startEmbeddedContent( currentSlide );
+
 		updateControls();
 		updateProgress();
 
@@ -1419,6 +1423,38 @@ var Reveal = (function(){
 
 	}
 
+	/**
+	 * Start playback of any embedded content inside of
+	 * the targeted slide.
+	 */
+	function startEmbeddedContent( slide ) {
+
+		if( slide ) {
+			toArray( slide.querySelectorAll( 'video, audio' ) ).forEach( function( el ) {
+				if( !el.hasAttribute( 'data-ignore' ) ) {
+					el.play();
+				}
+			} );
+		}
+
+	}
+
+	/**
+	 * Stop playback of any embedded content inside of
+	 * the targeted slide.
+	 */
+	function stopEmbeddedContent( slide ) {
+
+		if( slide ) {
+			toArray( slide.querySelectorAll( 'video, audio' ) ).forEach( function( el ) {
+				if( !el.hasAttribute( 'data-ignore' ) ) {
+					el.pause();
+				}
+			} );
+		}
+
+	}
+
 	/**
 	 * Reads the current URL (hash) and navigates accordingly.
 	 */

Filskillnaden har hållts tillbaka eftersom den är för stor
+ 1 - 1
js/reveal.min.js


Vissa filer visades inte eftersom för många filer har ändrats