fix edge case in background transitions (closes #604)

This commit is contained in:
Hakim El Hattab committed 2013-10-30 13:09:46 -04:00
1 parent 89cc3f3a29
commit fcf91ec261
2 files changed
+34 -28

No files matched your search

+32 -26
View File
@@ -122,7 +122,7 @@ var Reveal = (function(){
previousSlide,
currentSlide,
previousBackgroundHash,
previousBackground,
// 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
@@ -309,6 +309,9 @@ var Reveal = (function(){
// Read the initial hash
readURL();
// Update all backgrounds
updateBackground( true );
// Notify listeners that the presentation is ready but use a 1ms
// timeout to ensure it's not fired synchronously after #initialize()
setTimeout( function() {
@@ -444,7 +447,6 @@ 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 ) {
@@ -455,6 +457,8 @@ var Reveal = (function(){
else {
element.style.background = data.background;
}
element.setAttribute( 'data-background-hash', data.background + data.backgroundSize + data.backgroundImage + data.backgroundColor + data.backgroundRepeat + data.backgroundPosition + data.backgroundTransition );
}
// Additional and optional background properties
@@ -1640,7 +1644,7 @@ var Reveal = (function(){
updateControls();
updateProgress();
updateBackground();
updateBackground( true );
}
@@ -1891,8 +1895,11 @@ var Reveal = (function(){
/**
* Updates the background elements to reflect the current
* slide.
*
* @param {Boolean} includeAll If true, the backgrounds of
* all vertical slides (not just the present) will be updated.
*/
function updateBackground() {
function updateBackground( includeAll ) {
var currentBackground = null;
@@ -1904,51 +1911,50 @@ var Reveal = (function(){
// states of their slides (past/present/future)
toArray( dom.background.childNodes ).forEach( function( backgroundh, h ) {
backgroundh.className = 'slide-background ';
if( h < indexh ) {
backgroundh.className += horizontalPast;
backgroundh.className = 'slide-background ' + horizontalPast;
}
else if ( h > indexh ) {
backgroundh.className += horizontalFuture;
backgroundh.className = 'slide-background ' + horizontalFuture;
}
else {
backgroundh.className += 'present';
backgroundh.className = 'slide-background present';
// Store a reference to the current background element
currentBackground = backgroundh;
}
toArray( backgroundh.childNodes ).forEach( function( backgroundv, v ) {
if( includeAll || h === indexh ) {
toArray( backgroundh.childNodes ).forEach( function( backgroundv, v ) {
backgroundv.className = 'slide-background ';
if( v < indexv ) {
backgroundv.className = 'slide-background past';
}
else if ( v > indexv ) {
backgroundv.className = 'slide-background future';
}
else {
backgroundv.className = 'slide-background present';
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;
}
// 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 previousBackgroundHash = previousBackground ? previousBackground.getAttribute( 'data-background-hash' ) : null;
var currentBackgroundHash = currentBackground.getAttribute( 'data-background-hash' );
if( currentBackgroundHash === previousBackgroundHash ) {
if( currentBackgroundHash && currentBackgroundHash === previousBackgroundHash && currentBackground !== previousBackground ) {
dom.background.classList.add( 'no-transition' );
}
previousBackgroundHash = currentBackgroundHash;
previousBackground = currentBackground;
}
// Allow the first background to apply without transition
+2 -2
View File
@@ -1,8 +1,8 @@
/*!
* reveal.js 2.6.0-dev (2013-10-30, 12:19)
* reveal.js 2.6.0-dev (2013-10-30, 13:07)
* http://lab.hakim.se/reveal-js
* MIT licensed
*
* Copyright (C) 2013 Hakim El Hattab, http://hakim.se
*/
var Reveal=function(){"use strict";function a(a){if(b(),!bc.transforms2d&&!bc.transforms3d)return document.body.setAttribute("class","no-transforms"),void 0;window.addEventListener("load",C,!1);var d=Reveal.getQueryHash();"undefined"!=typeof d.dependencies&&delete d.dependencies,l(Yb,a),l(Yb,d),s(),c()}function b(){bc.transforms3d="WebkitPerspective"in document.body.style||"MozPerspective"in document.body.style||"msPerspective"in document.body.style||"OPerspective"in document.body.style||"perspective"in document.body.style,bc.transforms2d="WebkitTransform"in document.body.style||"MozTransform"in document.body.style||"msTransform"in document.body.style||"OTransform"in document.body.style||"transform"in document.body.style,bc.requestAnimationFrameMethod=window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame,bc.requestAnimationFrame="function"==typeof bc.requestAnimationFrameMethod,bc.canvas=!!document.createElement("canvas").getContext,Sb=navigator.userAgent.match(/(iphone|ipod|android)/gi)}function c(){function a(){c.length&&head.js.apply(null,c),d()}for(var b=[],c=[],e=0,f=Yb.dependencies.length;f>e;e++){var g=Yb.dependencies[e];(!g.condition||g.condition())&&(g.async?c.push(g.src):b.push(g.src),"function"==typeof g.callback&&head.ready(g.src.match(/([\w\d_\-]*)\.?js$|[^\\\/]*$/i)[0],g.callback))}b.length?(head.ready(a),head.js.apply(null,b)):a()}function d(){f(),e(),i(),bb(),setTimeout(function(){ac.slides.classList.remove("no-transition"),Zb=!0,u("ready",{indexh:Nb,indexv:Ob,currentSlide:Qb})},1)}function e(){var a=m(document.querySelectorAll(Vb));a.forEach(function(a){var b=m(a.querySelectorAll("section"));b.forEach(function(a,b){b>0&&a.classList.add("future")})})}function f(){ac.theme=document.querySelector("#theme"),ac.wrapper=document.querySelector(".reveal"),ac.slides=document.querySelector(".reveal .slides"),ac.slides.classList.add("no-transition"),ac.background=g(ac.wrapper,"div","backgrounds",null),ac.progress=g(ac.wrapper,"div","progress","<span></span>"),ac.progressbar=ac.progress.querySelector("span"),g(ac.wrapper,"aside","controls",'<div class="navigate-left"></div><div class="navigate-right"></div><div class="navigate-up"></div><div class="navigate-down"></div>'),g(ac.wrapper,"div","state-background",null),g(ac.wrapper,"div","pause-overlay",null),ac.controls=document.querySelector(".reveal .controls"),ac.controlsLeft=m(document.querySelectorAll(".navigate-left")),ac.controlsRight=m(document.querySelectorAll(".navigate-right")),ac.controlsUp=m(document.querySelectorAll(".navigate-up")),ac.controlsDown=m(document.querySelectorAll(".navigate-down")),ac.controlsPrev=m(document.querySelectorAll(".navigate-prev")),ac.controlsNext=m(document.querySelectorAll(".navigate-next"))}function g(a,b,c,d){var e=a.querySelector("."+c);return e||(e=document.createElement(b),e.classList.add(c),null!==d&&(e.innerHTML=d),a.appendChild(e)),e}function h(){function a(a,b){var c={background:a.getAttribute("data-background"),backgroundSize:a.getAttribute("data-background-size"),backgroundImage:a.getAttribute("data-background-image"),backgroundColor:a.getAttribute("data-background-color"),backgroundRepeat:a.getAttribute("data-background-repeat"),backgroundPosition:a.getAttribute("data-background-position"),backgroundTransition:a.getAttribute("data-background-transition")},d=document.createElement("div");return d.setAttribute("data-background-hash",c.background+c.backgroundSize+c.backgroundImage+c.backgroundColor+c.backgroundRepeat+c.backgroundPosition+c.backgroundTransition),d.className="slide-background",c.background&&(/^(http|file|\/\/)/gi.test(c.background)||/\.(svg|png|jpg|jpeg|gif|bmp)$/gi.test(c.background)?d.style.backgroundImage="url("+c.background+")":d.style.background=c.background),c.backgroundSize&&(d.style.backgroundSize=c.backgroundSize),c.backgroundImage&&(d.style.backgroundImage='url("'+c.backgroundImage+'")'),c.backgroundColor&&(d.style.backgroundColor=c.backgroundColor),c.backgroundRepeat&&(d.style.backgroundRepeat=c.backgroundRepeat),c.backgroundPosition&&(d.style.backgroundPosition=c.backgroundPosition),c.backgroundTransition&&d.setAttribute("data-background-transition",c.backgroundTransition),b.appendChild(d),d}r()&&document.body.classList.add("print-pdf"),ac.background.innerHTML="",ac.background.classList.add("no-transition"),m(document.querySelectorAll(Vb)).forEach(function(b){var c;c=r()?a(b,b):a(b,ac.background),m(b.querySelectorAll("section")).forEach(function(b){r()?a(b,b):a(b,c)})}),Yb.parallaxBackgroundImage?(ac.background.style.backgroundImage='url("'+Yb.parallaxBackgroundImage+'")',ac.background.style.backgroundSize=Yb.parallaxBackgroundSize,setTimeout(function(){ac.wrapper.classList.add("has-parallax-background")},1)):(ac.background.style.backgroundImage="",ac.wrapper.classList.remove("has-parallax-background"))}function i(a){var b=document.querySelectorAll(Ub).length;if(ac.wrapper.classList.remove(Yb.transition),"object"==typeof a&&l(Yb,a),bc.Line truncated
var Reveal=function(){"use strict";function a(a){if(b(),!bc.transforms2d&&!bc.transforms3d)return document.body.setAttribute("class","no-transforms"),void 0;window.addEventListener("load",C,!1);var d=Reveal.getQueryHash();"undefined"!=typeof d.dependencies&&delete d.dependencies,l(Yb,a),l(Yb,d),s(),c()}function b(){bc.transforms3d="WebkitPerspective"in document.body.style||"MozPerspective"in document.body.style||"msPerspective"in document.body.style||"OPerspective"in document.body.style||"perspective"in document.body.style,bc.transforms2d="WebkitTransform"in document.body.style||"MozTransform"in document.body.style||"msTransform"in document.body.style||"OTransform"in document.body.style||"transform"in document.body.style,bc.requestAnimationFrameMethod=window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame,bc.requestAnimationFrame="function"==typeof bc.requestAnimationFrameMethod,bc.canvas=!!document.createElement("canvas").getContext,Sb=navigator.userAgent.match(/(iphone|ipod|android)/gi)}function c(){function a(){c.length&&head.js.apply(null,c),d()}for(var b=[],c=[],e=0,f=Yb.dependencies.length;f>e;e++){var g=Yb.dependencies[e];(!g.condition||g.condition())&&(g.async?c.push(g.src):b.push(g.src),"function"==typeof g.callback&&head.ready(g.src.match(/([\w\d_\-]*)\.?js$|[^\\\/]*$/i)[0],g.callback))}b.length?(head.ready(a),head.js.apply(null,b)):a()}function d(){f(),e(),i(),bb(),W(!0),setTimeout(function(){ac.slides.classList.remove("no-transition"),Zb=!0,u("ready",{indexh:Nb,indexv:Ob,currentSlide:Qb})},1)}function e(){var a=m(document.querySelectorAll(Vb));a.forEach(function(a){var b=m(a.querySelectorAll("section"));b.forEach(function(a,b){b>0&&a.classList.add("future")})})}function f(){ac.theme=document.querySelector("#theme"),ac.wrapper=document.querySelector(".reveal"),ac.slides=document.querySelector(".reveal .slides"),ac.slides.classList.add("no-transition"),ac.background=g(ac.wrapper,"div","backgrounds",null),ac.progress=g(ac.wrapper,"div","progress","<span></span>"),ac.progressbar=ac.progress.querySelector("span"),g(ac.wrapper,"aside","controls",'<div class="navigate-left"></div><div class="navigate-right"></div><div class="navigate-up"></div><div class="navigate-down"></div>'),g(ac.wrapper,"div","state-background",null),g(ac.wrapper,"div","pause-overlay",null),ac.controls=document.querySelector(".reveal .controls"),ac.controlsLeft=m(document.querySelectorAll(".navigate-left")),ac.controlsRight=m(document.querySelectorAll(".navigate-right")),ac.controlsUp=m(document.querySelectorAll(".navigate-up")),ac.controlsDown=m(document.querySelectorAll(".navigate-down")),ac.controlsPrev=m(document.querySelectorAll(".navigate-prev")),ac.controlsNext=m(document.querySelectorAll(".navigate-next"))}function g(a,b,c,d){var e=a.querySelector("."+c);return e||(e=document.createElement(b),e.classList.add(c),null!==d&&(e.innerHTML=d),a.appendChild(e)),e}function h(){function a(a,b){var c={background:a.getAttribute("data-background"),backgroundSize:a.getAttribute("data-background-size"),backgroundImage:a.getAttribute("data-background-image"),backgroundColor:a.getAttribute("data-background-color"),backgroundRepeat:a.getAttribute("data-background-repeat"),backgroundPosition:a.getAttribute("data-background-position"),backgroundTransition:a.getAttribute("data-background-transition")},d=document.createElement("div");return d.className="slide-background",c.background&&(/^(http|file|\/\/)/gi.test(c.background)||/\.(svg|png|jpg|jpeg|gif|bmp)$/gi.test(c.background)?d.style.backgroundImage="url("+c.background+")":d.style.background=c.background,d.setAttribute("data-background-hash",c.background+c.backgroundSize+c.backgroundImage+c.backgroundColor+c.backgroundRepeat+c.backgroundPosition+c.backgroundTransition)),c.backgroundSize&&(d.style.backgroundSize=c.backgroundSize),c.backgroundImage&&(d.style.backgroundImage='url("'+c.backgroundImage+'")'),c.backgroundColor&&(d.style.backgroundColor=c.backgroundColor),c.backgroundRepeat&&(d.style.backgroundRepeat=c.backgroundRepeat),c.backgroundPosition&&(d.style.backgroundPosition=c.backgroundPosition),c.backgroundTransition&&d.setAttribute("data-background-transition",c.backgroundTransition),b.appendChild(d),d}r()&&document.body.classList.add("print-pdf"),ac.background.innerHTML="",ac.background.classList.add("no-transition"),m(document.querySelectorAll(Vb)).forEach(function(b){var c;c=r()?a(b,b):a(b,ac.background),m(b.querySelectorAll("section")).forEach(function(b){r()?a(b,b):a(b,c)})}),Yb.parallaxBackgroundImage?(ac.background.style.backgroundImage='url("'+Yb.parallaxBackgroundImage+'")',ac.background.style.backgroundSize=Yb.parallaxBackgroundSize,setTimeout(function(){ac.wrapper.classList.add("has-parallax-background")},1)):(ac.background.style.backgroundImage="",ac.wrapper.classList.remove("has-parallax-background"))}function i(a){var b=document.querySelectorAll(Ub).length;if(ac.wrapper.classList.remove(Yb.transition),"object"==typeof a&&l(Yb,Line truncated