diff --git a/js/plax.js b/js/plax.js index 8c202f2..c5cddfe 100644 --- a/js/plax.js +++ b/js/plax.js @@ -75,8 +75,8 @@ // no can-doesville, babydoll, we need pixels or top/left as initial values (it mightbe possible to construct a temporary image from the background-image property and get the dimensions and run some numbers, but that'll almost definitely be slow) return } - layer.startX = x[2] || 0 - layer.startY = y[2] || 0 + layer.originX = layer.startX = x[2] || 0 + layer.originY = layer.startY = y[2] || 0 } else { // Figure out where the element is positioned, then reposition it from the top/left @@ -87,8 +87,8 @@ 'right' :'', 'bottom':'' }) - layer.startX = this.offsetLeft - layer.startY = this.offsetTop + layer.originX = layer.startX = this.offsetLeft + layer.originY = layer.startY = this.offsetTop } layer.startX -= layer.inversionFactor * Math.floor(layer.xRange/2) @@ -237,6 +237,18 @@ disable: function(opts){ $(document).unbind('mousemove.plax') window.ondeviceorientation = undefined + if (opts && typeof opts.restorePositions === 'boolean' && opts.restorePositions) { + for(var i = layers.length; i--;) { + layer = layers[i] + if(layers[i].background) { + layer.obj.css('background-position', layer.originX+'px '+layer.originY+'px') + } else { + layer.obj + .css('left', layer.originX) + .css('top', layer.originY) + } + } + } if (opts && typeof opts.clearLayers === 'boolean' && opts.clearLayers) layers = [] } } diff --git a/readme.md b/readme.md index 5e04e81..cf224ed 100644 --- a/readme.md +++ b/readme.md @@ -94,6 +94,8 @@ Disable parallaxing. __Parameters__ +`restorePositions` — Boolean: (optional) resets all previously defined layers to their original positions when plax is deactivated. + `clearLayers` — Boolean: (optional) clears all previously defined layers when disabling.