lazy load all slide backgrounds

This commit is contained in:
Hakim El Hattab
2014-04-27 15:39:11 +02:00
parent 0140a15bae
commit 7158c12eff
3 changed files with 25 additions and 0 deletions

View File

@ -528,6 +528,8 @@ var Reveal = (function(){
createBackground( slidev, backgroundStack );
}
backgroundStack.classList.add( 'stack' );
} );
} );
@ -2279,8 +2281,14 @@ var Reveal = (function(){
*/
function showSlide( slide ) {
// Show the slide element
slide.style.display = 'block';
// Show the corresponding background element
var indices = getIndices( slide );
var background = getSlideBackground( indices.h, indices.v );
background.style.display = 'block';
// Media elements with data-src attributes
toArray( slide.querySelectorAll( 'img[data-src], video[data-src], audio[data-src], iframe[data-src]' ) ).forEach( function( element ) {
element.setAttribute( 'src', element.getAttribute( 'data-src' ) );
@ -2312,8 +2320,14 @@ var Reveal = (function(){
*/
function hideSlide( slide ) {
// Hide the slide element
slide.style.display = 'none';
// Hide the corresponding background element
var indices = getIndices( slide );
var background = getSlideBackground( indices.h, indices.v );
background.style.display = 'none';
}
/**
@ -2618,6 +2632,9 @@ var Reveal = (function(){
// Now that we know which the horizontal slide is, get its index
h = Math.max( horizontalSlides.indexOf( slideh ), 0 );
// Assume we're not vertical
v = 0;
// If this is a vertical slide, grab the vertical index
if( isVertical ) {
v = Math.max( toArray( slide.parentNode.querySelectorAll( 'section' ) ).indexOf( slide ), 0 );