diff options
author | Michał Smoliński <michal.smolinski@gmail.com> | 2013-09-10 21:23:10 +0200 |
---|---|---|
committer | Michał Smoliński <michal.smolinski@gmail.com> | 2013-09-10 21:23:10 +0200 |
commit | 2b5c06c4ef3002381c1007160f8ab60b4b2bd641 (patch) | |
tree | bb7925620b99546e6cd789cacd0718ae73ea5b1d /js/reveal.js | |
parent | 79340908f451ea77b364b1955928664defbd3bf6 (diff) | |
download | fosdem-2018-presentation-2b5c06c4ef3002381c1007160f8ab60b4b2bd641.tar fosdem-2018-presentation-2b5c06c4ef3002381c1007160f8ab60b4b2bd641.tar.gz |
Added parallax scrolling background
Diffstat (limited to 'js/reveal.js')
-rw-r--r-- | js/reveal.js | 56 |
1 files changed, 54 insertions, 2 deletions
diff --git a/js/reveal.js b/js/reveal.js index e1cd623..6562e65 100644 --- a/js/reveal.js +++ b/js/reveal.js @@ -88,6 +88,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, @@ -466,6 +472,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 ); + + } } @@ -1467,8 +1492,35 @@ 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; + + dom.wrapper.style.backgroundPositionX = horizontalOffset + 'px'; + + + var slideHeight = parseInt(dom.wrapper.offsetHeight, 10); + var verticalSlideCount = currentVerticalSlides.length; + var verticalOffset = verticalSlideCount > 0 ? -(bgHeight - slideHeight)/(verticalSlideCount-1) * v : 0; + + dom.wrapper.style.backgroundPositionY = verticalOffset + 'px'; + } + + //////////////////////////////////// // Show fragment, if specified if( typeof f !== 'undefined' ) { var fragments = sortFragments( currentSlide.querySelectorAll( '.fragment' ) ); |