Browse Source

gifs now restart when their slide container is shown

Hakim El Hattab 10 năm trước cách đây
mục cha
commit
49f462e6ce
2 tập tin đã thay đổi với 19 bổ sung0 xóa
  1. 3 0
      index.html
  2. 16 0
      js/reveal.js

+ 3 - 0
index.html

@@ -201,6 +201,9 @@
 							<pre><code style="word-wrap: break-word;">&lt;section data-background-video="video.mp4,video.webm"&gt;</code></pre>
 						</div>
 					</section>
+					<section data-background="http://i.giphy.com/90F8aUepslB84.gif">
+						<h2>... and GIFs!</h2>
+					</section>
 				</section>
 
 				<section data-transition="slide" data-background="#4d7e65" data-background-transition="zoom">

+ 16 - 0
js/reveal.js

@@ -2580,6 +2580,15 @@
 				currentVideo.play();
 			}
 
+			var backgroundImageURL = currentBackground.style.backgroundImage || '';
+
+			// Restart GIFs (doesn't work in Firefox)
+			if( /\.gif/i.test( backgroundImageURL ) ) {
+				currentBackground.style.backgroundImage = '';
+				window.getComputedStyle( currentBackground ).opacity;
+				currentBackground.style.backgroundImage = backgroundImageURL;
+			}
+
 			// Don't transition between identical backgrounds. This
 			// prevents unwanted flicker.
 			var previousBackgroundHash = previousBackground ? previousBackground.getAttribute( 'data-background-hash' ) : null;
@@ -2826,6 +2835,13 @@
 	function startEmbeddedContent( slide ) {
 
 		if( slide && !isSpeakerNotes() ) {
+			// Restart GIFs
+			toArray( slide.querySelectorAll( 'img[src$=".gif"]' ) ).forEach( function( el ) {
+				// Setting the same unchanged source like this was confirmed
+				// to work in Chrome, FF & Safari
+				el.setAttribute( 'src', el.getAttribute( 'src' ) );
+			} );
+
 			// HTML5 media elements
 			toArray( slide.querySelectorAll( 'video, audio' ) ).forEach( function( el ) {
 				if( el.hasAttribute( 'data-autoplay' ) ) {