diff options
author | Hakim El Hattab <hakim.elhattab@gmail.com> | 2013-10-30 12:22:00 -0400 |
---|---|---|
committer | Hakim El Hattab <hakim.elhattab@gmail.com> | 2013-10-30 12:22:00 -0400 |
commit | 89cc3f3a29c1b18ac716dde86dac8c81090ddf61 (patch) | |
tree | ebf49116efbc88d8d219d29c0ecb8fd6bf572c4d /js/reveal.js | |
parent | 080ae79b540c5cb9c16e1613322fec1f9c730b34 (diff) | |
download | perl-software-in-gnu-guix-89cc3f3a29c1b18ac716dde86dac8c81090ddf61.tar perl-software-in-gnu-guix-89cc3f3a29c1b18ac716dde86dac8c81090ddf61.tar.gz |
don't transition between identical backgrounds
Diffstat (limited to 'js/reveal.js')
-rw-r--r-- | js/reveal.js | 52 |
1 files changed, 47 insertions, 5 deletions
diff --git a/js/reveal.js b/js/reveal.js index e7debb5..a69a91f 100644 --- a/js/reveal.js +++ b/js/reveal.js @@ -122,6 +122,8 @@ var Reveal = (function(){ previousSlide, currentSlide, + previousBackgroundHash, + // Slides may hold a data-state attribute which we pick up and apply // as a class to the body. This list contains the combined state of // all current slides. @@ -442,6 +444,7 @@ var Reveal = (function(){ }; var element = document.createElement( 'div' ); + element.setAttribute( 'data-background-hash', data.background + data.backgroundSize + data.backgroundImage + data.backgroundColor + data.backgroundRepeat + data.backgroundPosition + data.backgroundTransition ); element.className = 'slide-background'; if( data.background ) { @@ -1891,24 +1894,63 @@ var Reveal = (function(){ */ function updateBackground() { + var currentBackground = null; + + // Reverse past/future classes when in RTL mode + var horizontalPast = config.rtl ? 'future' : 'past', + horizontalFuture = config.rtl ? 'past' : 'future'; + // Update the classes of all backgrounds to match the // states of their slides (past/present/future) toArray( dom.background.childNodes ).forEach( function( backgroundh, h ) { - // Reverse past/future classes when in RTL mode - var horizontalPast = config.rtl ? 'future' : 'past', - horizontalFuture = config.rtl ? 'past' : 'future'; + backgroundh.className = 'slide-background '; - backgroundh.className = 'slide-background ' + ( h < indexh ? horizontalPast : h > indexh ? horizontalFuture : 'present' ); + if( h < indexh ) { + backgroundh.className += horizontalPast; + } + else if ( h > indexh ) { + backgroundh.className += horizontalFuture; + } + else { + backgroundh.className += 'present'; + + // Store a reference to the current background element + currentBackground = backgroundh; + } toArray( backgroundh.childNodes ).forEach( function( backgroundv, v ) { - backgroundv.className = 'slide-background ' + ( v < indexv ? 'past' : v > indexv ? 'future' : 'present' ); + backgroundv.className = 'slide-background '; + + if( v < indexv ) { + backgroundv.className += 'past'; + } + else if ( v > indexv ) { + backgroundv.className += 'future'; + } + else { + backgroundv.className += 'present'; + + // Only if this is the present horizontal and vertical slide + if( h === indexh ) currentBackground = backgroundv; + } } ); } ); + // Don't transition between identical backgrounds. This + // prevents unwanted flicker. + if( currentBackground ) { + var currentBackgroundHash = currentBackground.getAttribute( 'data-background-hash' ); + if( currentBackgroundHash === previousBackgroundHash ) { + dom.background.classList.add( 'no-transition' ); + } + + previousBackgroundHash = currentBackgroundHash; + } + // Allow the first background to apply without transition setTimeout( function() { dom.background.classList.remove( 'no-transition' ); |