aboutsummaryrefslogtreecommitdiffhomepage
path: root/js/reveal.js
diff options
context:
space:
mode:
authorHakim El Hattab2013-09-15 17:45:27 -0400
committerHakim El Hattab2013-09-15 17:45:27 -0400
commit86216ac645d8bb696d090a90d5280dd8f963a44a (patch)
tree81a2171e6057fbaa2fc52a0e0c93eca42506b362 /js/reveal.js
parent36061b43bacb49ca83ebcbb8d419e36548439640 (diff)
use 'url()'-free path when specifying parallax image, refactor so that parallax is applied to background class, remove unused attributes #595
Diffstat (limited to 'js/reveal.js')
-rw-r--r--js/reveal.js32
1 files changed, 17 insertions, 15 deletions
diff --git a/js/reveal.js b/js/reveal.js
index f962f51..60a02e8 100644
--- a/js/reveal.js
+++ b/js/reveal.js
@@ -93,7 +93,7 @@ var Reveal = (function(){
backgroundTransition: 'default', // default/linear/none
// Parallax background image
- parallaxBackgroundImage: '', // CSS syntax, e.g. "url('a.jpg')"
+ parallaxBackgroundImage: '', // CSS syntax, e.g. "a.jpg"
// Parallax background size
parallaxBackgroundSize: '', // CSS syntax, e.g. "3000px 2000px"
@@ -476,24 +476,27 @@ var Reveal = (function(){
} );
- // Add parallax background if specified so
- var parallaxBackgroundImage = config.parallaxBackgroundImage,
- parallaxBackgroundSize = config.parallaxBackgroundSize;
+ // Add parallax background if specified
+ if( config.parallaxBackgroundImage ) {
- if( parallaxBackgroundImage ) {
- dom.wrapper.style.background = parallaxBackgroundImage;
- dom.wrapper.style.backgroundSize = parallaxBackgroundSize;
+ dom.background.style.backgroundImage = 'url("' + config.parallaxBackgroundImage + '")';
+ dom.background.style.backgroundSize = config.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 );
+ dom.wrapper.classList.add( 'has-parallax-background' );
}, 1 );
}
+ else {
+
+ dom.background.style.backgroundImage = '';
+ dom.wrapper.classList.remove( 'has-parallax-background' );
+
+ }
}
@@ -1888,13 +1891,12 @@ var Reveal = (function(){
*/
function updateParallax() {
- // Animate parallax background
- if( dom.wrapper.getAttribute( 'data-parallax-background' ) || config.parallaxBackgroundImage ) {
+ if( config.parallaxBackgroundImage ) {
var horizontalSlides = document.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR ),
verticalSlides = document.querySelectorAll( VERTICAL_SLIDES_SELECTOR );
- var backgroundSize = dom.wrapper.style.backgroundSize.split( ' ' ),
+ var backgroundSize = dom.background.style.backgroundSize.split( ' ' ),
backgroundWidth, backgroundHeight;
if( backgroundSize.length === 1 ) {
@@ -1905,15 +1907,15 @@ var Reveal = (function(){
backgroundHeight = parseInt( backgroundSize[1], 10 );
}
- var slideWidth = dom.wrapper.offsetWidth;
+ var slideWidth = dom.background.offsetWidth;
var horizontalSlideCount = horizontalSlides.length;
var horizontalOffset = -( backgroundWidth - slideWidth ) / ( horizontalSlideCount-1 ) * indexh;
- var slideHeight = dom.wrapper.offsetHeight;
+ var slideHeight = dom.background.offsetHeight;
var verticalSlideCount = verticalSlides.length;
var verticalOffset = verticalSlideCount > 0 ? -( backgroundHeight - slideHeight ) / ( verticalSlideCount-1 ) * indexv : 0;
- dom.wrapper.style.backgroundPosition = horizontalOffset + 'px ' + verticalOffset + 'px';
+ dom.background.style.backgroundPosition = horizontalOffset + 'px ' + verticalOffset + 'px';
}