move parallax code to separate method #595
This commit is contained in:
parent
347a907041
commit
8399e828db
2 changed files with 42 additions and 27 deletions
65
js/reveal.js
65
js/reveal.js
|
@ -1496,31 +1496,6 @@ var Reveal = (function(){
|
||||||
// Store references to the previous and current slides
|
// Store references to the previous and current slides
|
||||||
currentSlide = currentVerticalSlides[ indexv ] || currentHorizontalSlide;
|
currentSlide = currentVerticalSlides[ indexv ] || currentHorizontalSlide;
|
||||||
|
|
||||||
// Animate parallax background
|
|
||||||
if( dom.wrapper.getAttribute( 'data-parallax-background' ) || config.parallaxBackgroundImage ) {
|
|
||||||
var bs = dom.wrapper.style.backgroundSize.split( ' ' ),
|
|
||||||
bgWidth, bgHeight;
|
|
||||||
|
|
||||||
if( bs.length === 1 ) {
|
|
||||||
bgWidth = bgHeight = parseInt( bs[0], 10 );
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
bgWidth = parseInt( bs[0], 10 );
|
|
||||||
bgHeight = parseInt( bs[1], 10 );
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
var slideWidth = dom.wrapper.offsetWidth;
|
|
||||||
var horizontalSlideCount = horizontalSlides.length;
|
|
||||||
var horizontalOffset = -( bgWidth - slideWidth ) / ( horizontalSlideCount-1 ) * h;
|
|
||||||
|
|
||||||
var slideHeight = dom.wrapper.offsetHeight;
|
|
||||||
var verticalSlideCount = currentVerticalSlides.length;
|
|
||||||
var verticalOffset = verticalSlideCount > 0 ? -( bgHeight - slideHeight ) / ( verticalSlideCount-1 ) * v : 0;
|
|
||||||
|
|
||||||
dom.wrapper.style.backgroundPosition = horizontalOffset + 'px ' + verticalOffset + 'px';
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////
|
////////////////////////////////////
|
||||||
// Show fragment, if specified
|
// Show fragment, if specified
|
||||||
if( typeof f !== 'undefined' ) {
|
if( typeof f !== 'undefined' ) {
|
||||||
|
@ -1583,6 +1558,7 @@ var Reveal = (function(){
|
||||||
updateControls();
|
updateControls();
|
||||||
updateProgress();
|
updateProgress();
|
||||||
updateBackground();
|
updateBackground();
|
||||||
|
updateParallax();
|
||||||
|
|
||||||
// Update the URL hash
|
// Update the URL hash
|
||||||
writeURL();
|
writeURL();
|
||||||
|
@ -1905,6 +1881,45 @@ var Reveal = (function(){
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates the position of the parallax background based
|
||||||
|
* on the current slide index.
|
||||||
|
*/
|
||||||
|
function updateParallax() {
|
||||||
|
|
||||||
|
// Animate parallax background
|
||||||
|
if( dom.wrapper.getAttribute( 'data-parallax-background' ) || config.parallaxBackgroundImage ) {
|
||||||
|
|
||||||
|
var horizontalSlides = document.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR );
|
||||||
|
var currentHorizontalSlide = horizontalSlides[ indexh ],
|
||||||
|
currentVerticalSlides = currentHorizontalSlide.querySelectorAll( 'section' );
|
||||||
|
|
||||||
|
var backgroundSize = dom.wrapper.style.backgroundSize.split( ' ' ),
|
||||||
|
backgroundWidth, backgroundHeight;
|
||||||
|
|
||||||
|
if( backgroundSize.length === 1 ) {
|
||||||
|
backgroundWidth = backgroundHeight = parseInt( backgroundSize[0], 10 );
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
backgroundWidth = parseInt( backgroundSize[0], 10 );
|
||||||
|
backgroundHeight = parseInt( backgroundSize[1], 10 );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
var slideWidth = dom.wrapper.offsetWidth;
|
||||||
|
var horizontalSlideCount = horizontalSlides.length;
|
||||||
|
var horizontalOffset = -( backgroundWidth - slideWidth ) / ( horizontalSlideCount-1 ) * indexh;
|
||||||
|
|
||||||
|
var slideHeight = dom.wrapper.offsetHeight;
|
||||||
|
var verticalSlideCount = currentVerticalSlides.length;
|
||||||
|
var verticalOffset = verticalSlideCount > 0 ? -( backgroundHeight - slideHeight ) / ( verticalSlideCount-1 ) * indexv : 0;
|
||||||
|
|
||||||
|
dom.wrapper.style.backgroundPosition = horizontalOffset + 'px ' + verticalOffset + 'px';
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determine what available routes there are for navigation.
|
* Determine what available routes there are for navigation.
|
||||||
*
|
*
|
||||||
|
|
4
js/reveal.min.js
vendored
4
js/reveal.min.js
vendored
File diff suppressed because one or more lines are too long
Loading…
Reference in a new issue