diff options
author | Hakim El Hattab <hakim.elhattab@gmail.com> | 2013-09-15 14:44:45 -0400 |
---|---|---|
committer | Hakim El Hattab <hakim.elhattab@gmail.com> | 2013-09-15 14:44:45 -0400 |
commit | 2fc0dfa8e189a924a0ea77780e13537a02ff4e01 (patch) | |
tree | 5eac71dd0553d117c855b8da7522d6d9dc337c3e /js/reveal.js | |
parent | 1fb85d4df6a5b5b971d3a1beaff2a659bab72470 (diff) | |
parent | 2bd228534b9e667ec465131ff35b09e0b41fe890 (diff) | |
download | fosdem-2018-presentation-2fc0dfa8e189a924a0ea77780e13537a02ff4e01.tar fosdem-2018-presentation-2fc0dfa8e189a924a0ea77780e13537a02ff4e01.tar.gz |
merge parallax into dev, remove default image #595
Diffstat (limited to 'js/reveal.js')
-rw-r--r-- | js/reveal.js | 53 |
1 files changed, 51 insertions, 2 deletions
diff --git a/js/reveal.js b/js/reveal.js index 794911c..5894326 100644 --- a/js/reveal.js +++ b/js/reveal.js @@ -91,6 +91,12 @@ var Reveal = (function(){ // Transition style for full page slide backgrounds backgroundTransition: 'default', // default/linear/none + + // Parallax background image + parallaxBackgroundImage: '', // CSS syntax, e.g. "url('a.jpg')" + + // Parallax background size + parallaxBackgroundSize: '', // CSS syntax, e.g. "3000px 2000px" // Number of slides away from the current that are visible viewDistance: 3, @@ -469,6 +475,25 @@ var Reveal = (function(){ } ); } ); + + // Add parallax background if specified so + var parallaxBackgroundImage = config.parallaxBackgroundImage, + parallaxBackgroundSize = config.parallaxBackgroundSize; + + if (parallaxBackgroundImage) { + dom.wrapper.style.background = parallaxBackgroundImage; + dom.wrapper.style.backgroundSize = parallaxBackgroundSize; + + // Make sure the below properties are set on the element - these properties are + // needed for proper transitions to be set on the element via CSS. To remove + // annoying background slide-in effect when the presentation starts, apply + // these properties after short time delay + setTimeout( function() { + dom.wrapper.setAttribute('data-parallax-background', parallaxBackgroundImage); + dom.wrapper.setAttribute('data-parallax-background-size', parallaxBackgroundSize); + }, 1 ); + + } } @@ -1470,8 +1495,32 @@ var Reveal = (function(){ // Store references to the previous and current slides 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 = parseInt(dom.wrapper.offsetWidth, 10); + var horizontalSlideCount = horizontalSlides.length; + var horizontalOffset = -(bgWidth - slideWidth)/(horizontalSlideCount-1) * h; + + var slideHeight = parseInt(dom.wrapper.offsetHeight, 10); + 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 if( typeof f !== 'undefined' ) { var fragments = sortFragments( currentSlide.querySelectorAll( '.fragment' ) ); |